//在用ajax进行请求时,没有任何差错,但是总是返回error,不走succees,ajax代码如下 jQuery(document).ready(function($){ $.ajax({ url:"customerServlet?method=add&name="+encodeURI(encodeURI(name))+"&source="+encodeURI(encodeURI(source))+"&status="+encodeURI(encodeURI(status))+"&userID="+encodeURI(encodeURI(userID))+"&contactTime="+encodeURI(encodeURI(contactTime))+"&timeOfContact="+encodeURI(encodeURI(timeOfContact))+"&money="+encodeURI(encodeURI(money))+"&address="+encodeURI(encodeURI(address))+"&phone="+encodeURI(encodeURI(phone))+"&remarks="+encodeURI(encodeURI(remarks))+"&file="+encodeURI(encodeURI(file)),type:"post",dataType:"json",success:function(msg){ //alert(msg); console.log(msg+"1111"); },error:function(msg){ alert(msg); } }); });
这是因为dataType:"json",返回的必须是一个json,如果不是json,那么就会走error,如果返回的不是一个json,那么就需要把dataType:"json"这句话删掉
原文链接:https://www.f2er.com/ajax/162207.html