jquery post 同步异步总结
生活随笔
收集整理的這篇文章主要介紹了
jquery post 同步异步总结
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
最近在測(cè)試,發(fā)現(xiàn)有些效果不對(duì),最后發(fā)現(xiàn)是post的執(zhí)行順序問題,所以研究了下,寫了以下總結(jié)
1.post被請(qǐng)求多次,解決方法:
連接加入隨機(jī)數(shù) rand=""+Math.random()
$.post("/Control/webControl.ashx?rand ="+Math.random(), { Method: "LoginIn", Parems: ps }, function (data, textStatus) {$("#divOver").css("visibility", "hidden");switch (data) {case "1":window.location = '/default.aspx';break;case "0":$("#tips").text("找不到該用戶");u.focus();changevcode();errcount++;break;case "-1":$("#tips").text("用戶或密碼錯(cuò)誤");changevcode();c.val("").focus();errcount++;break;default:alert(data);}});2.因?yàn)閜ost默認(rèn)為異步請(qǐng)求,可是有時(shí)候我們會(huì)發(fā)現(xiàn),本來要求請(qǐng)求馬上出現(xiàn),可是異步會(huì)導(dǎo)致后面突然再執(zhí)行,這樣就出問題了
所以,我們需要加入
$.ajaxSetup({ async : false });3.如果需要有些同步有些異步,那么我們應(yīng)該使用最原始的ajax請(qǐng)求,然后把a(bǔ)sync設(shè)置為false
$.ajax({ type : "post", url : "register/RegisterState", data : "test=" + test, async : false, success : function(data){ data = eval("(" + data + ")"); aDataSet = data; } });?
總結(jié)
以上是生活随笔為你收集整理的jquery post 同步异步总结的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: RoboGuice入门
- 下一篇: 开源视频会议bigbluebutton