zoukankan      html  css  js  c++  java
  • JQuery ajax调用一直回调error函数

    使用jquery的ajax调用,发现一直回调error函数,ajax调用代码如下,后台返回是正确的,为什么会报错呢?
    1.  var descValue = $('#descEditArea').val();
    2.             descValue = descValue.replace(/ /g, '<br/>');
    3.             var url = "/network/KpiDescServlet";
    4.             $.ajax({
    5.                 url:url,
    6.                 type:"post",
    7.                 data:{rm:Math.random(),kpiId:"<%=kpiId%>",kpiType:"<%=kpiType%>",kpiDesc:descValue},
    8.                 dataType:"json",
    9.                 success:function(data){
    10.                     alert("修改成功");
    11.                     $("#desc").html(descValue);
    12.                      cancle();
    13.                 },
    14.                 error:function(){
    15.                     alert("修改失败");
    16.                             cancle();
    17.                 }
    18.             });  
    后来查找资料才发现,后台返回处设置的为ContentType"text/xml",而前台要求的是json,后台返回的不是一个正确的json,所以报错,修改方法为把前台的dataType修改为text
    1. response.setContentType("text/xml;charset=UTF-8");
    2. response.setHeader("Cache-Control", "no-cache");
    3. PrintWriter out = null;
    4. out = response.getWriter();
    5. out.println(result);


  • 相关阅读:
    LVS---服务器集群系统
    I/O的基本概念
    rsync+cron同步文件服务
    IAAS、PAAS、SAAS及公有云、私有云概念
    Python3456学习结构
    Python列表常用函数解析
    Python字符串常用函数详解
    验证码生成
    Python随机数生成random.randint()与np.random.randint()
    python在线&离线安装第三库的方法
  • 原文地址:https://www.cnblogs.com/CafeMing/p/6249114.html
Copyright © 2011-2022 走看看