liamoco Posted December 9, 2010 Share Posted December 9, 2010 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 More sharing options...
liamoco Posted December 9, 2010 Author Share Posted December 9, 2010 So somehow I need to get the response into a variable inside of the ajaxPost function Link to comment https://forums.phpfreaks.com/topic/221151-jquery-function-return/#findComment-1145089 Share on other sites More sharing options...
schilly Posted December 9, 2010 Share Posted December 9, 2010 is your php script returning a value? success: function(response){ alert( response); } Link to comment https://forums.phpfreaks.com/topic/221151-jquery-function-return/#findComment-1145094 Share on other sites More sharing options...
liamoco Posted December 9, 2010 Author Share Posted December 9, 2010 yes, the path is correct and returning the correct value Link to comment https://forums.phpfreaks.com/topic/221151-jquery-function-return/#findComment-1145095 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.