Javascript XML 解析错误:在控制台 FF 中找不到根元素位置

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46487220/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 03:28:05  来源:igfitidea点击:

XML Parsing Error: no root element found Location in Console FF

javascriptjqueryxmlasp.net-mvc

提问by Pawe? Groński

I'm use ASP.NET MVC end I take this error only in FF. Why I take this error message? What is the cause of this? I Don't understand where the source of this error. Anyone have any thoughts?

我正在使用 ASP.NET MVC 端我只在 FF 中出现此错误。为什么我会收到此错误消息?这是什么原因?我不明白这个错误的根源在哪里。有人有什么想法吗?

enter image description here

enter image description here

Next Error: enter image description here

下一个错误: enter image description here

回答by Master Yoda

Check this linkfor more information

检查此链接以获取更多信息

Based on my research, the error message is only generated by FireFox when the render page is blank in Internet. For some reason, .NET generates a response type of "application/xml" when it creates an empty page. Firefox parses the file as XML and finding no root element, spits out the error message.

根据我的研究,该错误消息仅在 Internet 中呈现页面为空白时由 FireFox 生成。出于某种原因,.NET 在创建空页面时会生成“application/xml”响应类型。Firefox 将文件解析为 XML 并没有找到根元素,并吐出错误消息。

in other words, this is a known Firefox issue

换句话说,这是一个已知的 Firefox 问题

回答by Ovini

Hoping this might help someone.... I changed the type of return value in Action method and it worked. More details can be found in this article.

希望这可能对某人有所帮助.... 我在 Action 方法中更改了返回值的类型并且它起作用了。更多细节可以在这篇文章中找到。

Changed from

改自

return Ok();

to

return Json("Ok");

回答by anderspitman

I fixed this in my app by setting the Content-Typeheader on the server to text/plain. Like this in Node:

我通过将Content-Type服务器上的标头设置为text/plain. 在 Node 中是这样的:

res.setHeader('Content-Type', 'text/plain');

Use whatever MIME type is appropriate for your data, ie application/json, etc.

使用适合您的数据的任何 MIME 类型,即application/json等。

回答by Shahriar

We were getting this error when POSTing an axios call. And our test server was not in the

我们在发布 axios 调用时收到此错误。我们的测试服务器不在

allowed-origin: 

list of hosts. Adding our server to allowed-origin in the application.yml resolved the issue.

主机列表。将我们的服务器添加到 application.yml 中的 allowed-origin 解决了该问题。

回答by GerardV

This can happen too, if you have a [ValidateAntiForgeryToken] attribute on your controller action and try to submit the form without an actual token. You can render the token explicitly with

如果您的控制器操作具有 [ValidateAntiForgeryToken] 属性并尝试在没有实际令牌的情况下提交表单,则也可能发生这种情况。您可以使用显式呈现令牌

@Html.AntiForgeryToken()

which is the preferred solution or remove the validation attribute.

这是首选解决方案或删除验证属性。