XMLHTT prequest.status返回0和responseText的空白在Firefox 3.5 [英] XMLHTTPRequest.status returns 0 and responseText is blank in FireFox 3.5

查看:144
本文介绍了XMLHTT prequest.status返回0和responseText的空白在Firefox 3.5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打一个第三方URL获得XML响应并显示reposne到我的网页。 我与地位,200和的readyState为4在IE和Safari浏览器的一个适当的反应。 但在FF3.5和克罗默我得到XMLHTT prequest状态为0,reponseText之际,一个空字符串。我试了很多选项写正常XMLHTT prequest阿贾克斯code,以及使用原型1.5版本的js文件这个ajax请求,但仍然在FF 3.5的地位和reponseText保持不变为0,空字符串。

任何帮助如何解决究竟是引起此问题将大大AP preciated这个问题还是什么。 我也试图执行我的code当地以及部署到Web服务器仍然在FF repsonse是一样的。

下面是我的code段

 <脚本类型=文/ JavaScript的SRC =prototype_ajax.js>< / SCRIPT>

<脚本类型=文/ JavaScript的LANGUAGE =JavaScript的>

新的Ajax.Request(我把我的网址在这里,{
    方法:'得到',
    的onSuccess:函数(运输){

       VAR resultDoc = transport.responseText;
       VAR rootObj =的loadXML(resultDoc);

    },
    onFailure:函数(运输){
       警报(论失败+运输)

    }
});

功能的loadXML(XMLFILE){
   VAR xmlDocElement = NULL;
   VAR xmlDoc中= NULL;

   如果(window.ActiveXObject){
     尝试 {
        // code IE浏览器
        xmlDoc中=新的ActiveXObject(Microsoft.XMLDOM);
        xmlDoc.async = FALSE;
        xmlDoc.loadXML(XMLFILE);
     }赶上(五){
        警报(内抓::+ e.message);
     }
   } 其他 {
     // code为Mozilla的火狐,Opera等
     分析器=新的DOMParser();
     xmlDoc中= parser.parseFromString(XMLFILE,为text / xml);

     //xmlDocElement=xmlDoc.documentElement;
   }

   //警报(loadXML的值+ xmlDoc中)
   返回xmlDoc中;
}

< / SCRIPT>
 

解决方案

看起来你已经撞到了同源策略。你必须使用相对路径,否则大多数浏览器只会返回一个空的的responseText

下面的堆栈溢出后很可能也涉及到你的问题:

作为一个可能的解决方法,你可以建立一个非常简单的反向代理(带的mod_proxy 如果你使用Apache)。这将允许您使用相对路径在你的AJAX请求,而HTTP服务器将作为任何远程位置的代理。

基本配置指令设置一个反向代理在mod_proxy的是增强了ProxyPass。您通常会使用它,如下所示:

 的ProxyPass /网络服务/ http://third-party.com/web-services/
 

在这种情况下,浏览器将请求 /web-services/service.xml ,但服务器将通过作为代理 http://third-party.com/web-services/service.xml 。

I am trying to hit a third party URL to get the XML response and to show the reposne into my webpage. I get a proper response with status as 200 and readystate as 4 in IE and Safari browsers. But In FF3.5 and Crome i get XMLHTTPRequest status as 0 and reponseText comes as a blank string. I tried many options writing the normal XMLHTTPRequest Ajax code as well as using Prototype 1.5 version js file for this ajax request, but still the status and reponseText in FF 3.5 remains the same as 0 and blank string.

Any help how to resolve this issue or what exactly is causing this issue would be greatly appreciated. I had also tried to execute my code locally as well as deploying to webserver still the repsonse in FF is same.

Below is my code snippet

<script type="text/javascript" src="prototype_ajax.js"></script>

<script type="text/javascript" language="javascript">

new Ajax.Request("I place my URL Here", {
    method: 'get',
    onSuccess : function(transport){

       var resultDoc = transport.responseText;
       var rootObj = loadXML(resultDoc);

    },
    onFailure : function(transport){
       alert(' On Failure '+transport)

    }
});

function loadXML(xmlFile) {
   var xmlDocElement =null;
   var xmlDoc = null;

   if (window.ActiveXObject) {
     try {
        // code for IE
        xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
        xmlDoc.async=false;
        xmlDoc.loadXML(xmlFile);
     } catch (e) {
        alert("inside catch::"+e.message);
     }
   } else {
     // code for Mozilla, Firefox, Opera, etc.
     parser=new DOMParser();
     xmlDoc=parser.parseFromString(xmlFile,"text/xml");

     //xmlDocElement=xmlDoc.documentElement;
   }

   //alert('loadXML value  '+xmlDoc)
   return xmlDoc;
}

</script>

解决方案

It looks like you have bumped into the same origin policy. You have to use a relative path, otherwise most browsers will simply return an empty responseText.

The following Stack Overflow post is probably also related to your problem:

As one possible workaround, you could set up a very simple reverse proxy (with mod_proxy if you are using Apache). This would allow you to use relative paths in your AJAX request, while the HTTP server would be acting as a proxy to any "remote" location.

The fundamental configuration directive to set up a reverse proxy in mod_proxy is the ProxyPass. You would typically use it as follows:

ProxyPass     /web-services/     http://third-party.com/web-services/

In this case, the browser would be requesting /web-services/service.xml but the server would serve this by acting as a proxy to http://third-party.com/web-services/service.xml.

这篇关于XMLHTT prequest.status返回0和responseText的空白在Firefox 3.5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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