因爲$.post() 和 $.get() 默認是 異步請求,若是須要同步請求,則能夠進行以下使用:
在$.post()前把ajax設置爲同步:$.ajaxSettings.async = false;
在$.post()後把ajax改回爲異步:$.ajaxSettings.async = true;ajax
$.ajaxSettings.async = false; $.post(url, {id:id}, function(res) { if (res.code == 0) { alert(res.message); e.stopPropagation(); e.preventDefault(); $(this).attr('href','jacascript::void(0)'); } },"json");