我一直收到这个错误,XML解析错误:语法错误,但网站运行正常 [英] I keep getting this error, XML Parsing error: syntax error but still the website runs fine

查看:143
本文介绍了我一直收到这个错误,XML解析错误:语法错误,但网站运行正常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是开发网站的新手。
我知道我必须在web.xml文件中映射servlet。
web.xml文件是这个

I am new to developing websites. I know that I have to map servlets in the web.xml file. The web.xml file is this

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
    <display-name>TestApp</display-name>
    <welcome-file-list>
     <welcome-file>index.html</welcome-file>
     <welcome-file>index.htm</welcome-file>
     <welcome-file>index.jsp</welcome-file>
     <welcome-file>default.html</welcome-file>
     <welcome-file>default.htm</welcome-file>
     <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>
    <servlet>
     <servlet-name>Serve</servlet-name>
     <servlet-class>Serve</servlet-class>
    </servlet>
    <servlet-mapping>
     <servlet-name>Serve</servlet-name>
     <url-pattern>/TestApp</url-pattern>
    </servlet-mapping>
   </web-app>

但是当我调用jquery $ .ajax()函数时,我收到此错误。

But when I call the jquery $.ajax() function, I get this error.


XML解析错误:语法错误
位置: http:// localhost:8080 / TestApp / Serve
第1行,第1列:

XML Parsing Error: syntax error Location: http://localhost:8080/TestApp/Serve Line Number 1, Column 1:

AJAX电话是

    $.ajax({
    url: "Serve",
    type: "POST",
    success: function(out){
        alert(out);
    },
    error: function(){
        alert("No");
    }
});

问题是servlet仍然正常运行。警报(out)按预期工作。请解释为什么浏览器显示错误,请告诉我一个解决方案。

The problem is the servlet still runs fine. The alert(out) works as expected. Please explain why the browser is showing the error and please tell me a solution.

如果这是一个重复的问题,请提供原始问题的链接。

If this is a duplicate question please give a link to the original question.

推荐答案

我最近遇到了同样的问题。 jQuery似乎正在正确地处理数据和dataType,但是它返回了语法错误,这解释了为什么你的代码按预期执行但仍然向控制台输出错误。

I recently encountered the same issue. jQuery appeared to be handling the data and the dataType correctly, but instead it was Firefox returning the syntax error, which explains why your code was executing as intended but still printing an error to the console.

如果查看开发人员控制台,可以看到Firefox正在将纯文本数据解释为另一种格式(可能是XML)。 Firefox厌倦了将数据解析为XML,但不能,因为它不是有效的XML导致语法错误被打印到控制台。

If you look in the developer console, you can see that Firefox is interpreting the plain text data as another format (likely XML). Firefox tires to parse the data as XML, but can't because it's not valid XML which results in "Syntax error" being printed to the console.

对此的解析我的问题是编辑服务器,所以返回下面的标题:

The resolution to this problem for me was editing the server so it returned the below header:


Content-Type:text / plain

这似乎只是Firefox的问题,Chrome没有遇到这个问题。这里有一个Firefox漏洞似乎触及了这个问题。

This only appeared to be an issue with Firefox, Chrome did not encounter this issue. There is a Firefox bug here which seems to touch on the issue.

source

这篇关于我一直收到这个错误,XML解析错误:语法错误,但网站运行正常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆