sameold
sameold

Reputation: 19262

getting a response from $.post

I'm calling an ajax page using $.post.

$.post("ajaxpage.php", $("#theform").serialize());

How can I echo the response that the page returned? I tried saving to a var, but it's not giving me the response.

var resp = $.post("ajaxpage.php", $("#theform").serialize());
console.log(resp);

Upvotes: 1

Views: 214

Answers (2)

Ben
Ben

Reputation: 10104

$.post("ajaxpage.php", $("#theform").serialize(), function(data, status, xhr) {
    console.log(data);
});

Upvotes: 4

Jayantha Lal Sirisena
Jayantha Lal Sirisena

Reputation: 21376

http://api.jquery.com/jQuery.post/

$.post("ajaxpage.php", $("#theform").serialize(),function(data){
  $('#yourDivId').html(data);//data is what you recived from the server

});

Upvotes: 3

Related Questions