1

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?

2
  • 1
    $.ajax(url:"myurl.html",data: yourdata, success:function(data){....}); on the success yo can do whatever you want after response Commented Jan 9, 2012 at 19:55
  • I think the question is pointing more towards using data outside of the success function. Something King Arthur may have tried (and which wouldn't work) is var response_data = $.ajax(); expecting $.ajax() to return 'data' but it actually returns a 'jqXHR' object. Commented Feb 12, 2012 at 2:11

3 Answers 3

4

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
  }
});
Sign up to request clarification or add additional context in comments.

Comments

1

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 
  }
});

More Information

Comments

0

You pass a function to the .ajax() as the success argument. That function will be called with the data returned from the call.

edit Damn, lost another drag-race.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.