记录一个浪费我一天时间的ajax问题

前端之家收集整理的这篇文章主要介绍了记录一个浪费我一天时间的ajax问题前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
<script  type="text/javascript">
$(function() {
	//登录
	$.ajaxSetup({ async: false });
	$('#loginBtn').click(function() {
		login();
	});
});

function login() {
	$.getJSON('<%=renderResponse.encodeURL(loginUrl.toString())%>',function(data){
		alert(data.result);
	});
}
</script>
function login() {
	$.ajax({
        type: "POST",url: "<%=renderResponse.encodeURL(loginUrl.toString())%>",dataType: "json",async: false,success: function(data){
        	alert(data.result);
        },error : function(XMLHttpRequest,textStatus,errorThrown){
			alert("网络连接出错!");
 			alert(XMLHttpRequest.status);
 			alert(XMLHttpRequest.readyState);    
            alert(textStatus);
			return false;
		}
      });
}

In the ajax operation just add

async: false,

after

datatype: "json",sans-serif; line-height:18px"> and that should solve your problem. Chrome has issue handling asynchronus calls.


--------------------------------------------------------------------

You can also use the following before making your call:

$.ajaxSetup( { "async": false } );

I do not know the scope of the "async" property,I suspect that it is a global config. So consider whether you want to change this back to true after your synchronous call.

example:

3rdPartyObject.getCustomValue = function { $.ajaxSetup( { false } ); var result = $.getJSON('myUrl'); $.ajaxSetup( { true } ); return result; }
resourceResponse.setContentType("application/json;charset=utf-8"); resourceResponse.getWriter().print("{\"result\":\"ok\"}"); 原文链接:https://www.f2er.com/ajax/166494.html

猜你在找的Ajax相关文章