Jump to content

jQuery function return


liamoco

Recommended Posts

I have put the following bit of code inside a function called ajaxPost

function ajaxPost(data, path)
{	
$.ajax({
type: "POST",
url: path,
data: "data=" + data,
cache: false,
success: function(response){
	return response;
}
});

//somehow return response variable here
}

 

var phpLogin = ajaxPost("test", 'php/login.php');
alert(phpLogin);

 

 

When I call the function, and alert the response is keep getting "undefined". I think I know why it isn't working - because the response is being return to the wrong function. What can I do to make this work

 

Link to comment
https://forums.phpfreaks.com/topic/221151-jquery-function-return/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.