語法
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");