I am using a .ajax() function to call on a page and passing in data to it. What I don't understand is how to get the data and use it in the page that was called upon. Is there a function that I can call to retract the data?
3 Answers
http://api.jquery.com/jQuery.ajax/
$.ajax({
url: "test.html", //give your URL here
data: {name:"your name"} , //(optional) if you wish you can send this data to server, just like this.
success: function(data){
$('body').prepend(data); //here is your data
}
});
Comments
Description
Yes you can access the data that gets back from the page using jQuery's ajax callback.
I suggest your page return jSon data. If you provide which technique you use on the server side PHP, Asp.NET or other we can provide a full working example. Or did you want to load html ?
Sample
$.ajax({
url: "test.html",
context: document.body,
success: function(data){
// data
}
});
var response_data = $.ajax(); expecting $.ajax() to return 'data' but it actually returns a 'jqXHR' object.