jQuery ajax 不适用于 Mozilla

发布于 2024-09-11 00:24:07 字数 1433 浏览 8 评论 0原文

我有以下脚本

$.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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

叶落知秋 2024-09-18 00:24:07

我认为您正在执行跨服务器请求(更重要的是,跨域请求),因此,您需要执行额外的安全操作。

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,调试作为对象更好,然后您可以检查返回的对象。

console.log({ "error": XMLHttpRequest, "error2": textStatus,  "error3": errorThrown });

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.

console.log({ "error": XMLHttpRequest, "error2": textStatus,  "error3": errorThrown });
哀由 2024-09-18 00:24:07

尝试从查询本身设置内容类型:

$.ajax({
   type:"GET",
   url:"views/jquery/js/private/visual_constructor/proxy.php",
   data:null,
   timeout:55000,
   contentType: "application/xml;charset=UTF-8",
   dataType:"xml",
   error:function(XMLHttpRequest, textStatus, errorThrown){
         alert("error="+XMLHttpRequest+" error2="+textStatus+" error3="+errorThrown);
   },
   success:function(response){                      
         alert('sucess');
   }
});

Try setting the content type from the query itself:

$.ajax({
   type:"GET",
   url:"views/jquery/js/private/visual_constructor/proxy.php",
   data:null,
   timeout:55000,
   contentType: "application/xml;charset=UTF-8",
   dataType:"xml",
   error:function(XMLHttpRequest, textStatus, errorThrown){
         alert("error="+XMLHttpRequest+" error2="+textStatus+" error3="+errorThrown);
   },
   success:function(response){                      
         alert('sucess');
   }
});
带上头具痛哭 2024-09-18 00:24:07

您以以下方式打开:

<xs:annotation>

并以以下方式结束:

</xs:annotatin>

修正拼写错误,问题就会消失。

You open with:

<xs:annotation>

And close with:

</xs:annotatin>

Fix the spelling error and the problem should go away.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文