How to store the received the data from an remote php file in an variable using jquery.
I receive the data using
$.post("test.php", {query: ""+inputString+""}, function(data){
alert(data);
});
}
It works i can receive the data inside the function(data) but can i sore the data in an variable and use it in another function some thing like
var data = $.post("test.php", {query: ""+inputString+""});
You can’t do that because AJAX is asynchronous, meaning that the result is only available inside the success callback which might run much later than the actual
$.postcall. So instead of trying to store the result into a variable, use the success callback which is the only reliable place to consume the results of an AJAX request to call some other method for example and do some processing on those results: