036_jQuery Ajax全局回调函数
1. ajaxStart()方法
1.1. ajaxStart()方法在AJAX請(qǐng)求發(fā)送前執(zhí)行函數(shù)。
1.2. 語(yǔ)法
$(selector).ajaxStart(function(even))1.3. 參數(shù)
2. ajaxSend()方法
2.1. ajaxSend()方法在AJAX請(qǐng)求開(kāi)始時(shí)執(zhí)行函數(shù)。
2.2. 語(yǔ)法
$(selector).ajaxSend(function(even,jqXHR,options))2.3. 參數(shù)
3. ajaxSuccess()方法
3.1. ajaxSuccess()方法在AJAX請(qǐng)求成功時(shí)執(zhí)行函數(shù)。
3.2. 語(yǔ)法
$(selector).ajaxSuccess(function(even,jqXHR,options,response))3.3. 參數(shù)
4. ajaxError()方法
4.1. ajaxError()方法在AJAX請(qǐng)求發(fā)生錯(cuò)誤時(shí)執(zhí)行函數(shù)。
4.2. 語(yǔ)法
$(selector).ajaxError(function(even,jqXHR,options,error))4.3. 參數(shù)
5. ajaxComplete()方法
5.1. ajaxComplete()方法在AJAX請(qǐng)求完成時(shí)執(zhí)行函數(shù)。
5.2. 語(yǔ)法
$(selector).jQueryajaxComplete(function(even,jqXHR,options))5.3. 參數(shù)
6. ajaxStop()方法
6.1. ajaxStop()方法在AJAX請(qǐng)求結(jié)束時(shí)執(zhí)行函數(shù)。
6.2. 語(yǔ)法
$(selector).ajaxStop(function(even))6.3. 參數(shù)
7. 6個(gè)全局回調(diào)函數(shù)的運(yùn)行順序
7.1. 6個(gè)全局回調(diào)函數(shù)的運(yùn)行順序是: ajaxStart()、ajaxSend()、ajaxSuccess()/ajaxError()、ajaxComplete()和ajaxStop()。
8. 例子
8.1. 新建一個(gè)名為jQueryAjaxGlobalFunction動(dòng)態(tài)WEB工程
8.2. 新建test.json
{"data": {"code": 1, "info": "success", "msg": "請(qǐng)求成功。"}}8.3. 新建test.xml
<?xml version="1.0" encoding="UTF-8"?> <data><code>1</code><info>success</info><msg>請(qǐng)求成功。</msg> </data>8.4. 新建index.html
<!DOCTYPE html> <html><head><title>jQuery-Ajax的全局回調(diào)函數(shù)</title><meta charset="utf-8" /><script type="text/javascript" src="jquery.js"></script><script type="text/javascript">$(document).ready(function(){$(this).ajaxStart(function(even){console.log('-------ajaxStart Start-------------');for(var i = 0; i < arguments.length; i++){console.log(arguments[i]);} console.log('-------ajaxStart End-------------'); }).ajaxSend(function(even, jqXHR, options){console.log('-------ajaxSend Start-------------');for(var i = 0; i < arguments.length; i++){console.log(arguments[i]);} console.log('-------ajaxSend End-------------'); }).ajaxSuccess(function(even, jqXHR, options, response){console.log('-------ajaxSuccess Start-------------');for(var i = 0; i < arguments.length; i++){console.log(arguments[i]);} console.log('-------ajaxSuccess End-------------'); }).ajaxError(function(even, jqXHR, options, error){console.log('-------ajaxError Start-------------');for(var i = 0; i < arguments.length; i++){console.log(arguments[i]);} console.log('-------ajaxError End-------------'); }).ajaxComplete(function(even, jqXHR, options){console.log('-------ajaxComplete Start-------------');for(var i = 0; i < arguments.length; i++){console.log(arguments[i]);} console.log('-------ajaxComplete End-------------'); }).ajaxStop(function(even){console.log('-------ajaxStop Start-------------');for(var i = 0; i < arguments.length; i++){console.log(arguments[i]);} console.log('-------ajaxStop End-------------'); });$('#btn1').click(function(){$.get('test.json');});$('#btn2').click(function(){$.post('test.xml');});$('#btn3').click(function(){$("#result").load("test.json");});$('#btn4').click(function(){$.ajax({url: 'test.xml',dataType: 'xml',cache: false});});});</script><style type="text/css">div {width: 450px;height: 100px;background-color: pink;}</style></head><body> <div id="result">結(jié)果區(qū)域</div><br /><button id="btn1">get test.json</button> <button id="btn2">post test.xml</button><br /><br /><button id="btn3">load test.json</button> <button id="btn4">ajax test.xml</button></body> </html>8.5. 運(yùn)行項(xiàng)目
《新程序員》:云原生和全面數(shù)字化實(shí)踐50位技術(shù)專家共同創(chuàng)作,文字、視頻、音頻交互閱讀總結(jié)
以上是生活随笔為你收集整理的036_jQuery Ajax全局回调函数的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 035_jQuery Ajax的ajax
- 下一篇: 037_jQuery Ajax序列化