jQuery的ajax,當async為false時,同步操作失敗。解決方案,jqueryasync

來源:互聯網
上載者:User

jQuery的ajax,當async為false時,同步操作失敗。解決方案,jqueryasync

引發失敗時代碼:

 $.ajax({                url : 'your url',                data:{name:value},                cache : false,                 async : true,                type : "POST",                dataType : 'json/xml/html',                success : function (result){                    return result;                }            });

解決方案:

 var ret = null;$.ajax({                url : 'your url',                data:{name:value},                cache : false,                 async : true,                type : "POST",                dataType : 'json/xml/html',                success : function (result){                    ret=result;                }            });return ret;


說明:

不要在success的回呼函數中直接return,具體原因後面在考察!!


$ajax()設定同步提交無效,代碼如下,設定了async:"false" 但還是非同步提交的

ajax本來的目的就是進行非同步作業, 而且最新的jquery版本甚至已經棄用了async參數.

如果你只是想利用ajax做伺服器的互動,不需要非同步重新整理效果,那可以用回呼函數.
 
jquery $ajax函數,中的async: "false", 不起作用幫忙看看

"false" 加了雙引號就是字串了,非空串就為true。

去掉雙引號。
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.