2011-07-27 31 views
1

如何使用jquery 1.6進行ajax/JSON調用並優雅地處理錯誤(如果有的話)。jQuery 1.6撥打JSON電話和處理錯誤

如果有人可以舉一個例子,那會很棒。

+3

你讀過的文檔? http://api.jquery.com/jQuery.ajax/ –

+0

不要忘記標記ans爲接受,如果你得到你想要的信息 –

回答

2

利用jQuery庫中的$ .ajax函數,您可以輕鬆處理錯誤。

像這樣的事情

$.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 
       }); 

要檢查deatil信息來源華南簡介Ajax的方法,你可以檢查此文章:http://pranayamr.blogspot.com/2011/07/jquery-ajax-calling-functions.html