jQuery ajax 不适用于 Mozilla
我有以下脚本
$.ajax({
type:"GET",
url:"views/jquery/js/private/visual_constructor/proxy.php",
data:null,
timeout:55000,
dataType:"xml",
error:function(XMLHttpRequest, textStatus, errorThrown){
alert("error="+XMLHttpRequest+" error2="+textStatus+" error3="+errorThrown);
},
success:function(response){
alert('sucess');
}
});
,proxy.php 的内容如下。
<?php
header('Content-type: application/xml');
echo file_get_contents('http://server.name/somefile.php');
?>
它连接到另一台服务器,其中 somefile.php
生成一些 xml 内容并打印它。
它在 Chrome 中完美运行,但在 Mozilla 中它会向我显示错误警报。
这里有什么问题吗?
更新 1
我正在使用 firebug,它说一切正常。即使它显示了服务器的响应。这是我的错误警报打印的内容:
error=[object XMLHttpRequest] error2=parsererror error3=parsererror
update 2
当我打开 http://server来自 Mozilla 的 .name/somefile.php 它向我显示了这条消息:
XML Parsing Error: not well-formed
Location: http://authoringtool/views/jquery/js/private/visual_constructor/proxy.php
Line Number 8, Column 94: <xs:annotation><xs:documentation xml:lang="en">Network Type</xs:documentation></xs:annotatin>
但是当我从 Chrome 打开它时,它并没有显示错误,而是打印了 somefile.php 的内容
I have following script
$.ajax({
type:"GET",
url:"views/jquery/js/private/visual_constructor/proxy.php",
data:null,
timeout:55000,
dataType:"xml",
error:function(XMLHttpRequest, textStatus, errorThrown){
alert("error="+XMLHttpRequest+" error2="+textStatus+" error3="+errorThrown);
},
success:function(response){
alert('sucess');
}
});
and the content of the proxy.php is following.
<?php
header('Content-type: application/xml');
echo file_get_contents('http://server.name/somefile.php');
?>
It connects to another server where somefile.php
generates some xml content and prints it.
It works perfectly in Chrome, but in Mozilla it shows me my error alert.
What is wrong here?
update 1
I am using firebug and it says that everything is just OK. Even it shows the response from the server. And here is what my error alert prints:
error=[object XMLHttpRequest] error2=parsererror error3=parsererror
update 2
When I open http://server.name/somefile.php from the Mozilla it shows me this message:
XML Parsing Error: not well-formed
Location: http://authoringtool/views/jquery/js/private/visual_constructor/proxy.php
Line Number 8, Column 94: <xs:annotation><xs:documentation xml:lang="en">Network Type</xs:documentation></xs:annotatin>
But again when I open it from Chrome it doesn't show me the error but prints the content of the somefile.php
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为您正在执行跨服务器请求(更重要的是,跨域请求),因此,您需要执行额外的安全操作。
https://developer.mozilla.org/En/HTTP_access_control
https://developer.mozilla.org/En/Server-Side_Access_Control
http://www.w3.org/TR/cors/
http://arunranga.com/examples/access-control/
Firebug
另外,使用 Firebug,调试作为对象更好,然后您可以检查返回的对象。
I think you're doing a cross-server request (more importantly, a cross-domain request ), and as such, you need to do extra security stuff.
https://developer.mozilla.org/En/HTTP_access_control
https://developer.mozilla.org/En/Server-Side_Access_Control
http://www.w3.org/TR/cors/
http://arunranga.com/examples/access-control/
Firebug
Also, with Firebug, debugging is better as objects, then you can inspect the returned objects.
尝试从查询本身设置内容类型:
Try setting the content type from the query itself:
您以以下方式打开:
并以以下方式结束:
修正拼写错误,问题就会消失。
You open with:
And close with:
Fix the spelling error and the problem should go away.