Jquery调用ajax参数说明
生活随笔
收集整理的這篇文章主要介紹了
Jquery调用ajax参数说明
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
代碼中有詳細注釋,直接上代碼。
注釋掉的選項,一般用不到,直接用最基本的部分就可以了。
$.ajax({// 請求的URLurl: '../Daily/Daily_Report',//HTTP method:"POST", "GET", "PUT"// 這樣寫也行 method: 'POST',type: "POST",// 發送到服務器的數據 data: {"user":"abc"},// default: true// 是否異步,默認是異步的//async: true,// default: true// 發送數據前,會將data屬性指定的object轉換成query string// 指定成false后,object的數據在后臺得不到//processData: true,// default: 'application/x-www-form-urlencoded; charset=UTF-8'// values: application/x-www-form-urlencoded, multipart/form-data, or text/plain// 發送給服務器的數據類型,UTF-8編碼是固定的,改不了的。// 設定為false,就是不設定contentType給服務器,可以省略//contentType: false,// 服務器返回的數據類型,不指定的話,jquery回根據服務器指定的MIME進行推斷。// 所以,如果服務器指定了MINE類型,可以省略//dataType:"json",// 發送前調用的函數// 如果返回false,將取消ajax請求//beforeSend: function (xhr, settings) {//},// 對返回數據的預處理// 這里的data是原始的response的數據,比success函數的data要早,// 如有需要,可以對返回的原始值進行處理,然后再返回data//dataFilter:function(data, type){//},// 成功時調用的函數// 這里的data已經是根據dataType,格式化好的數據,比如一個json對象。success: function (data, textStatus, xhr) {if (data !== null) {}},// 異常時調用的函數// Possible values for the second argument (besides null) are "timeout", "error", "abort", and "parsererror".// When an HTTP error occurs, errorThrown receives the textual portion of the HTTP status, such as "Not Found" or "Internal Server Error."error: function (xhr, textStatus, errorThrown) {},// ajax請求完成調用的函數,這個函數在success和error后調用,不論成功或失敗都要做的操作放在這里//textStatus:"success", "notmodified", "nocontent", "error", "timeout", "abort", or "parsererror"complete: function(xhr, textStatus){}});?
轉載于:https://www.cnblogs.com/xiashengwang/p/8085140.html
總結
以上是生活随笔為你收集整理的Jquery调用ajax参数说明的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: axios 的简单使用
- 下一篇: 函数闭包与装饰器