jQuery ajax - post() 方法

語法

jQuery.post(url,data,success(data, textStatus, jqXHR),dataType)

參數 描述
url 必需。規定把請求發送到哪個 URL。
data 可選。映射或字符串值。規定連同請求發送到服務器的數據。
success(data, textStatus, jqXHR) 可選。請求成功時執行的回調函數。
dataType

可選。規定預期的服務器響應的數據類型。

默認執行智能判斷(xml、json、script 或 html)。


如果由 jQuery.post() 發起的請求返回錯誤代碼,那麼不會有任何提示,除非腳本已調用了全局的 .ajaxError() 方法或者對於 jQuery 1.5,jQuery.post() 返回的 jqXHR 對象的 .error() 方法也可以用於錯誤處理。

$.post("test.action", { "func": "getNameAndTime" },
   function(data,textStatus,jqXHR){
     alert(data.name); // John 
  .success(function() { alert("second success"); })
  .error(function() { alert("error"); })
  .complete(function() { alert("complete"); });
}, "json");

發佈了30 篇原創文章 · 獲贊 4 · 訪問量 16萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章