开发者

$.ajax try catch

开发者 https://www.devze.com 2022-12-25 16:03 出处:网络
I have an $.ajax call that includes both a success and error condition: $(\'input[name=\"StateName\"]\').live(\'change\', function() {

I have an $.ajax call that includes both a success and error condition:

$('input[name="StateName"]').live('change', function() {
    var StateID = $(this).parents('tr').attr('id');
    var StateName = $(this).val();
    $.ajax({
        url: 'Remote/State.cfc'
        ,type: "POST"
        ,data: {
            'method': 'UpdateStateName'
            ,'StateID': StateID
            ,'StateName': StateName
        }
        ,success: function(result){
            if (isNaN(res开发者_如何学Pythonult)) {
                $('#msg').text(result).addClass('err');
            } else {
                $('#' + result + ' input[name="StateName"]').addClass('changed');
            };
        }
        ,error: function(msg){
            $('#msg').text('Connection error').addClass('err');
        }
    });
});

Q: Should I also wrap this in a try/catch?


There is no need for try catch, as that adds to redundancy.

on jQuery's side, they've done quite well on the error catching within their methods. As for your code, IMHO I don't see the need.


502 HTTP error can not be catch by jquery

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号