jQuery的ajax,当async为false时,同步操作失败。解决方式
引发失败时代码:
$.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。详细原因后面在考察!
!