JQuery ajax請求一直返回Error(parsererror)


[javascript]  view plain  copy
 
 print?
  1. $.ajax({  
  2.             type :"post",  
  3.             url :"busine_in.action",  
  4.             timeout : 40000,  
  5.             data: "centerid="+s,  
  6.             error : function(XMLHttpRequest, textStatus, errorThrown) {   
  7.                     alert(XMLHttpRequest.status);  
  8.                        alert(XMLHttpRequest.readyState);  
  9.                        alert(textStatus);  
  10.                 alert('讀取超時,請檢查網絡連接');  
  11.             },  
  12.             dataType : "json",  
  13.             success : function(data){  
  14.                 alert("1");  
  15.                  $("#select_div").hide();  
  16.                     str='<div style=" overflow:auto;height:430px;">';  
  17.                     str+='<table border="0" cellspacing="0" cellpadding="0" width="100%" class="table2 muma_list">';  
  18.                     str+='<tr>';  
  19.                     str+='<th align="left">區域</th>';  
  20.                     str+='</tr>';  
  21.                 $.each(data,function(i, n){  
  22.                 alert("2");alert(i);alert("n=="+n.length);  
  23.                  if ("list" == i){  
  24.                     str+='<tr>';  
  25.                     str+='<td><a href="javascript:unitedit(\''+n.areaId+'\')" title="點擊編輯">'+n.areaName+'</a></td>';  
  26.                     str+='</tr>';  
  27.                  }  
  28.                });  
  29.                     str+='</table>';  
  30.                     str+='</div>';  
  31.                     alert("3");  
  32.                     $("#select_div").html(str);  
  33.              }  
  34.           });  

上述的代碼一直進入error,並且

[javascript]  view plain  copy
 
 print?
  1. alert(textStatus);  

彈出的一直是parsererror

[javascript]  view plain  copy
 
 print?
  1. alert(XMLHttpRequest.status);  

彈出200正常

[javascript]  view plain  copy
 
 print?
  1. alert(XMLHttpRequest.readyState);  

彈出4正常

最后發現彈出parsererror的原因是類型的問題,也就是說可能是返回類型出問題了。果然進過查找,發現在struts.xml文件中的ajax請求的action中的result返回類型不是json

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM