jsp 解决ajax返回数据 parsererror

分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow

也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!

               

今天用ajax提交数据的时候,发现server接收正常,数据已经提交。

返回数据老报parsererror

最后查了一下说书返回的数据有问题。即

out.println("{'xx':'xxxxxx'}")

有问题。 然后查资料 调试一下 我发现我server提交的是一个jsp


<!doctype html><% String path = request.getContextPath(); pageContext.setAttribute("path", path); ReplyServlet reply = new ReplyServlet(); String action = request.getParameter("action"); if ("reply".equals(action)) {  reply.postReply(request);  //response.setContentType("text/json;charset=UTF-8");  out.write("{\"result\":\"true\",\"msg\":\"true\"}");  out.flush();  return; }

然后我调了一下

dataType改为 text  查看显示的值

<!doctype html>

{"result":"ok","msg":"true"}

-------------------------------------------------------至此原因已经找到

function submit_ajax(){  //alert(xx.toJSONString());  $.ajax( {           url:'index.jsp',// 跳转到 action           data:{               action : "reply",             tid : $("#tid").val(),                  energy : $("#game_coin").val(),                  content : $("#content").val()           },           type:'post',       //contentType: "application/json; charset=utf-8",      //cache:false,           dataType:'text',           success:function(data) {         alert(data);          if(data.msg =="true" ){                   // view("修改成功!");                   alert("修改成功!");                   window.location.reload();               }else{                   alert(data.msg);               }            },            complete : function(XMLHttpRequest, textStatus, errorThrown) {                 //alert(XMLHttpRequest.status);                  //alert(XMLHttpRequest.readyState);                  alert(textStatus);       }  }); 


           

给我老师的人工智能教程打call!http://blog.csdn.net/jiangjunshow

这里写图片描述

猜你喜欢

转载自blog.csdn.net/gruhgd/article/details/84065205