JQuery ajax調用一直回調error函數

使用jquery的ajax調用,發現一直回調error函數,ajax調用代碼以下,後臺返回是正確的,爲何會報錯呢?
    
    
    
    
 var descValue = $('#descEditArea').val();            descValue = descValue.replace(/\n/g, '<br/>');            var url = "/network/KpiDescServlet";            $.ajax({                url:url,                type:"post",                data:{rm:Math.random(),kpiId:"<%=kpiId%>",kpiType:"<%=kpiType%>",kpiDesc:descValue},                dataType:"json",                success:function(data){                    alert("修改爲功");                    $("#desc").html(descValue);                     cancle();                },                error:function(){                    alert("修改失敗");                            cancle();                }            });  
後來查找資料才發現,後臺返回處設置的爲ContentType"text/xml",而前臺要求的是json,後臺返回的不是一個正確的json,因此報錯,修改方法爲把前臺的dataType修改成text
    
    
    
    
response.setContentType("text/xml;charset=UTF-8");response.setHeader("Cache-Control", "no-cache");PrintWriter out = null;out = response.getWriter();out.println(result);
相關文章
相關標籤/搜索