jQuery 1.6 Make a JSON call and Handle errors
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
精彩评论