转自:https://blog.csdn.net/yiluoak_47/article/details/8190598###
[javascript] view plain copy print?
- $.ajax({
- type :"post",
- url :"busine_in.action",
- timeout : 40000,
- data: "centerid="+s,
- error : function(XMLHttpRequest, textStatus, errorThrown) {
- alert(XMLHttpRequest.status);
- alert(XMLHttpRequest.readyState);
- alert(textStatus);
- alert(\'读取超时,请检查网络连接\');
- },
- dataType : "json",
- success : function(data){
- alert("1");
- $("#select_div").hide();
- str=\'<div style=" overflow:auto;height:430px;">\';
- str+=\'<table border="0" cellspacing="0" cellpadding="0" width="100%" class="table2 muma_list">\';
- str+=\'<tr>\';
- str+=\'<th align="left">区域</th>\';
- str+=\'</tr>\';
- $.each(data,function(i, n){
- alert("2");alert(i);alert("n=="+n.length);
- if ("list" == i){
- str+=\'<tr>\';
- str+=\'<td><a href="javascript:unitedit(\\'\'+n.areaId+\'\\')" title="点击编辑">\'+n.areaName+\'</a></td>\';
- str+=\'</tr>\';
- }
- });
- str+=\'</table>\';
- str+=\'</div>\';
- alert("3");
- $("#select_div").html(str);
- }
- });
上述的代码一直进入error,并且
- alert(textStatus);
弹出的一直是parsererror
- alert(XMLHttpRequest.status);
弹出200正常
- alert(XMLHttpRequest.readyState);
弹出4正常
最后发现弹出parsererror的原因是类型的问题,也就是说可能是返回类型出问题了。果然进过查找,发现在struts.xml文件中的ajax请求的action中的result返回类型不是json