Handle 500 errors in JSON (jQuery)

前端 未结 5 1359
孤城傲影
孤城傲影 2020-12-28 14:35

This JSON request:

$.ajax({
    url:jSONurl+\'?orderID=\'+thisOrderID+\'&variationID=\'+thisVariationID+\'&quantity=\'+thisQuantity+\'&callback=?         


        
5条回答
  •  误落风尘
    2020-12-28 15:41

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

提交回复
热议问题