开发者

jQuery 1.6 Make a JSON call and Handle errors

开发者 https://www.devze.com 2023-03-23 11:29 出处:网络
How can i make a ajax/JSON call using jquery 1.6 and handle error开发者_高级运维s gracefully if any.

How can i make a ajax/JSON call using jquery 1.6 and handle error开发者_高级运维s gracefully if any.

If anybody could give an example, that would be great.


Make use of $.ajax function avaible in jquery library and you can handle error easily.

Something like this

 $.ajax({
                    type: "GET", //GET or POST or PUT or DELETE verb
                    url: ajaxUrl, // Location of the service
                    data: "", //Data sent to server
                    contentType: "", // content type sent to server
                    dataType: "json", //Expected data format from server
                    processdata: true, //True or False
                    success: function (json) {//On Successfull service call
                        var result = json.name;
                        $("#dvAjax").html(result);
                    },
                    error: ServiceFailed// When Service call fails
                });

To check deatil infomation abour the ajax method you can check this article : http://pranayamr.blogspot.com/2011/07/jquery-ajax-calling-functions.html

0

精彩评论

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