This JSON request:
$.ajax({
url:jSONurl+\'?orderID=\'+thisOrderID+\'&variationID=\'+thisVariationID+\'&quantity=\'+thisQuantity+\'&callback=?
Did you try statuscode
callback like
$.ajax({
statusCode: {
500: function() {
alert("Script exhausted");
}
}
});
I think you could catch it by adding this:
$.ajax({
statusCode: {
500: function() {
alert("error");
}
},
url:jSONurl+'?orderID='+thisOrderID+'&variationID='+thisVariationID+'&quantity='+thisQuantity+'&callback=?',
async: false,
type: 'POST',
dataType: 'json',
success: function(data) {
if (data.response == 'success'){
//show the tick. allow the booking to go through
$('#loadingSML'+thisVariationID).hide();
$('#tick'+thisVariationID).show();
}else{
//show the cross. Do not allow the booking to be made
$('#loadingSML'+thisVariationID).hide();
$('#cross'+thisVariationID).hide();
$('#unableToReserveError').slideDown();
//disable the form
$('#OrderForm_OrderForm input').attr('disabled','disabled');
}
},
error: function(data){
alert('error');
}
})
Check out the jqXHR Object docs. You could use the fail method to capture any errors.
Something like the following for your case:
$.post(jSONurl+'?orderID='+thisOrderID+'&variationID='+thisVariationID+'&quantity='+thisQuantity+'&callback=?')
.done(function(data){
if (data.response == 'success'){
//show the tick. allow the booking to go through
$('#loadingSML'+thisVariationID).hide();
$('#tick'+thisVariationID).show();
}else{
//show the cross. Do not allow the booking to be made
$('#loadingSML'+thisVariationID).hide();
$('#cross'+thisVariationID).hide();
$('#unableToReserveError').slideDown();
//disable the form
$('#OrderForm_OrderForm input').attr('disabled','disabled');
}
}, "json")
.fail(function(jqXHR, textStatus, errorThrown){
alert("Got some error: " + errorThrown);
});
I would also look into passing a json data string via post instead of attaching query variables:
$.post(jSONurl, $.toJSON({orderID: thisOrderID, variationID: thisVariationID, quantity: thisQuantity, callback: false}))
If you are using POST you can use something like this:
$.post('account/check-notifications')
.done(function(data) {
// success function
})
.fail(function(jqXHR){
if(jqXHR.status==500 || jqXHR.status==0){
// internal server error or internet connection broke
}
});
I removed the dataType:json from the ajax call and I was able to catch the error. In these situations I do not need the content of the returned jSON luckily; only to know that there is an error being returned so this will suffice for now. Firebug still has a hissy fit but I am at least able to perform some actions when there is an error
$.ajax({
url:'http://example.com/jsonservice/LiftieWeb/reserve?token=62e52d30e1aa70831c3f09780e8593f8&orderID='+thisOrderID+'&variationID='+reserveList+'&quantity='+thisQuantity+'&callback=?',
type: 'POST',
success: function(data) {
if (data.response == 'Success'){
//show the tick. allow the booking to go through
$('#loadingSML'+thisVariationID).hide();
$('#tick'+thisVariationID).show();
}else{
//show the cross. Do not allow the booking to be made
$('#loadingSML'+thisVariationID).hide();
$('#cross'+thisVariationID).hide();
$('#unableToReserveError').slideDown();
//disable the form
$('#OrderForm_OrderForm input').attr('disabled','disabled');
}
},
error: function(data){
alert('error');
}
})