-1

When the page loads i have setup a jquery $.post()

$.post("area.php", {'user': $('#state').val()},
function(info){
      //do something
});

So upon load the php is called and is there a way to know if no info is received due connection failure or similar?

Becky
  • 5,467
  • 9
  • 40
  • 73
  • as a suggestion, consider using `$('#the-form').serialize()` instead of manually building POST data. – zzzzBov May 13 '16 at 14:39

2 Answers2

3

Yes. You just have to add a 2nd function to what you already have or use the promises like.

$.post( "example.php", function() {
  alert( "success" );
})
.done(function() {
  alert( "second success" );
})
.fail(function() {
  alert( "error" );
})
.always(function() {
  alert( "finished" );
});

From: https://api.jquery.com/jquery.post/

oooyaya
  • 1,773
  • 1
  • 15
  • 39
  • $.post is just a shortcut for $.ajax which supplies the type="POST" part for you. $.ajax also exposes the entirety of the method whereas $.post may not include all things. – oooyaya May 13 '16 at 14:39
0

Try This :

$.post("area.php", { 'user': $('#state').val() }).done(function () {
    console.log("success");
})
.fail(function () {
    console.log("error");
});
Wasif Shahjahan
  • 346
  • 2
  • 9