1

我有以下脚本

$.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

我正在使用萤火虫,它说一切都很好。即使它显示来自服务器的响应。这是我的错误警报打印的内容:

error=[object XMLHttpRequest] error2=parsererror error3=parsererror

更新 2

当我从 Mozilla 打开http://server.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 的内容

4

3 回答 3

0

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

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

console.log({ "error": XMLHttpRequest, "error2": textStatus,  "error3": errorThrown });
于 2010-07-21T18:28:07.083 回答
0

你打开:

<xs:annotation>

并关闭:

</xs:annotatin>

修复拼写错误,问题应该会消失。

于 2011-05-21T13:02:18.197 回答
0

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

$.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');
   }
});
于 2010-07-21T18:50:30.090 回答