jQuery 封裝 ajax 的使用方法

2021-10-05 18:29:05 字數 786 閱讀 1950

jquery中 封裝的 ajax請求 有3種

1, $.get() get請求方式

引數有4個引數,必填引數是 url位址 其他引數都是選填引數,可以沒有

引數的形式是物件形式

$.get( 請求成功時執行的函式

})2, $.post() post請求方式

引數有4個引數,必填引數是 url位址 其他引數都是選填引數,可以沒有

引數的形式是物件形式

$.post( 請求成功時執行的函式

})3, $.ajax() 綜合方式

引數有 n 個引數,特別特別多,逐一介紹

常規get,post請求(不是跨域),常用引數

$.ajax( 傳參引數,必須是物件形式

datatype : json, 設定為json,會自動解析反應提中的json串

success : function(){} 請求成功執行的函式

不常用:

async : 設定是否非同步,預設值是true,非同步執行ajax請求

error : function(){} 請求錯誤時執行的函式

請求成功時不會執行

timeout : 設定時間,單位 毫秒

如果請求時間超過設定的時間,認為是請求失敗

必須是非同步執行

cache : 設定是否快取請求結果

預設值是 true,快取請求結果

必須是get方式,這個設定才起作用

post方式不會快取,設定也沒有效果

context : 指定 執行函式中 this的指向

})

Ajax原理及JQuery封裝的使用

建立xmlhttprequest物件var xhr new xmlhttprequest 設定請求報文 1.設定請求行 引數1為請求方式,引數2為請求位址 get方式 xhr.open get 01.php?name zs age 18 需要將傳送的資料拼接在位址後面 post方式 xhr.open...

jQuery 封裝 ajax 的使用方法

1,get請求方式 get 方法 get datatype json succsee function res url 請求的後台程式位址 data 傳送到後台的資料,物件格式 datatype 返回資料的型別,預設為string,如果為json,會自動解析後端返回的json串 succsee 請求...

jQuery 封裝 ajax 的使用方法

jquery封裝ajax請求有三種方式 一 get請求方式 get datatype 期望的資料型別,如果為json,會將後端返回的json串,自動解析,success function 請求成功時執行的函式 二 post請求方式 post datatype 期望的資料型別,如果為json,會將後端...