I have the following code which work fine in case of success and error. But what I want to do is make another ajax call in case of error. to some other URL . what is the correct way of doing it. I tried calling the ajax function again but it resulted in a javascript error
this is the sample of working code.
$('#save-walkin').die('vclick').live('vclick', function(e) {
e.preventDefault();
$.mobile.showPageLoadingMsg();
$.ajax({
url: 'http://www.someurl.com',
method: 'POST',
data: $('#form-createwalkin').serialize(),
success: function(){
$.mobile.hidePageLoadingMsg ();
document.location.href = "queue.php";
},
error: function(){
$.mobile.hidePageLoadingMsg ();
document.location.href = "queue.php";
}
});
return false;
});
Where as what I am trying to do is something like this. but It’s not working
$('#save-walkin').die('vclick').live('vclick', function(e) {
e.preventDefault();
$.mobile.showPageLoadingMsg();
$.ajax({
url: 'http://www.someurl.com',
method: 'POST',
data: $('#form-createwalkin').serialize(),
success: function(){
$.mobile.hidePageLoadingMsg ();
document.location.href = "queue.php";
},
error: function(){
$.ajax({
url: 'http://www.someotherurl.com',
method: 'POST',
data: $('#form-createwalkin').serialize(),
success: function(){
$.mobile.hidePageLoadingMsg ();
document.location.href = "queue.php";
},
error: function(){
$.mobile.hidePageLoadingMsg ();
document.location.href = "queue.php";
}
}
});
return false;
});
It’s just not formed correctly. It should look like this: