php版微信開(kāi)發(fā)之接收消息,自動(dòng)判斷及回復(fù)相應(yīng)消息的方法
663
2024-01-25
開(kāi)發(fā)過(guò)程中,AJAX的應(yīng)用應(yīng)該說(shuō)非常頻繁,當(dāng)然,jQuery的AJAX函數(shù)已經(jīng)非常好用,但是小編還是稍微整理下,方便不同需求下,可以簡(jiǎn)化輸入?yún)?shù),下面是實(shí)例代碼:
$(function(){ /** * ajax封裝 * url 發(fā)送請(qǐng)求的地址 * data 發(fā)送到服務(wù)器的數(shù)據(jù),數(shù)組存儲(chǔ),如:{"date": new Date().getTime(), "state": 1} * async 默認(rèn)值: true。默認(rèn)設(shè)置下,所有請(qǐng)求均為異步請(qǐng)求。如果需要發(fā)送同步請(qǐng)求,請(qǐng)將此選項(xiàng)設(shè)置為 false。 * 注意,同步請(qǐng)求將鎖住瀏覽器,用戶其它操作必須等待請(qǐng)求完成才可以執(zhí)行。 * type 請(qǐng)求方式("POST" 或 "GET"), 默認(rèn)為 "GET" * dataType 預(yù)期服務(wù)器返回的數(shù)據(jù)類(lèi)型,常用的如:xml、html、json、text * successfn 成功回調(diào)函數(shù) * errorfn 失敗回調(diào)函數(shù) */ jQuery.syncAjax=function(url, data, async, type, dataType, successfn, errorfn) { async = (async==null || async=="" || typeof(async)=="undefined")? "true" : async; type = (type==null || type=="" || typeof(type)=="undefined")? "post" : type; dataType = (dataType==null || dataType=="" || typeof(dataType)=="undefined")? "json" : dataType; data = (data==null || data=="" || typeof(data)=="undefined")? {"date": new Date().getTime()} : data; $.ajax({ type: type, async: async, data: data, url: url, dataType: dataType, success: function(d){ successfn(d); }, error: function(e){ errorfn(e); } }); }; /** * ajax封裝 * url 發(fā)送請(qǐng)求的地址 * data 發(fā)送到服務(wù)器的數(shù)據(jù),數(shù)組存儲(chǔ),如:{"date": new Date().getTime(), "state": 1} * successfn 成功回調(diào)函數(shù) */ jQuery.jsonAjax=function(url, data, successfn) { data = (data==null || data=="" || typeof(data)=="undefined")? {"date": new Date().getTime()} : data; $.ajax({ type: "post", data: data, url: url, dataType: "json", success: function(d){ successfn(d); } }); }; /** * ajax封裝 * url 發(fā)送請(qǐng)求的地址 * data 發(fā)送到服務(wù)器的數(shù)據(jù),數(shù)組存儲(chǔ),如:{"date": new Date().getTime(), "state": 1} * dataType 預(yù)期服務(wù)器返回的數(shù)據(jù)類(lèi)型,常用的如:xml、html、json、text * successfn 成功回調(diào)函數(shù) * errorfn 失敗回調(diào)函數(shù) */ jQuery.jsonAjax2=function(url, data, successfn, errorfn) { data = (data==null || data=="" || typeof(data)=="undefined")? {"date": new Date().getTime()} : data; $.ajax({ type: "post", data: data, url: url, dataType: "json", success: function(d){ successfn(d); }, error: function(e){ errorfn(e); } }); }; });
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持綠夏網(wǎng)。
#免責(zé)聲明#
本站[綠夏技術(shù)導(dǎo)航]提供的一切軟件、教程和內(nèi)容信息僅限用于學(xué)習(xí)和研究目的;不得將上述內(nèi)容用于商業(yè)或者非法用途,否則,一切后果請(qǐng)用戶自負(fù)。本站信息來(lái)自網(wǎng)絡(luò)收集整理,版權(quán)爭(zhēng)議與本站無(wú)關(guān)。您必須在下載后的24個(gè)小時(shí)之內(nèi),從您的電腦或手機(jī)中徹底刪除上述內(nèi)容。如果您喜歡該程序或內(nèi)容,請(qǐng)支持正版,購(gòu)買(mǎi)注冊(cè),得到更好的正版服務(wù)。我們非常重視版權(quán)問(wèn)題,如有侵權(quán)請(qǐng)郵件[admin@lxwl520.com]與我們聯(lián)系進(jìn)行刪除處理。敬請(qǐng)諒解!