prequest空的responseText

prequest空的responseText

本文介绍了从XMLHtt prequest空的responseText的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经写它运行良好,但返回一个空的responseText的XMLHtt prequest。

I have written an XMLHttpRequest which runs fine but returns an empty responseText.

中的JavaScript如下:

The javascript is as follows:

  var anUrl = "http://api.xxx.com/rates/csv/rates.txt";
  var myRequest = new XMLHttpRequest();

  callAjax(anUrl);

  function callAjax(url) {
     myRequest.open("GET", url, true);
     myRequest.onreadystatechange = responseAjax;
                 myRequest.setRequestHeader("Cache-Control", "no-cache");
     myRequest.send(null);
  }

  function responseAjax() {
     if(myRequest.readyState == 4) {
        if(myRequest.status == 200) {
            result = myRequest.responseText;
            alert(result);
            alert("we made it");
        } else {
            alert( " An error has occurred: " + myRequest.statusText);
        }
     }
  }

在code运行良好。我可以步行通过,我得到的readyState == 4和状态== 200,但responseText的始终是一片空白。

The code runs fine. I can walk through and I get the readyState == 4 and a status == 200 but the responseText is always blank.

我收到错误调度的日志错误(在Safari中调试):GetProperties中,我似乎无法找到参考。

I am getting a log error (in Safari debug) of Error dispatching: getProperties which I cannot seem to find reference to.

我已经在本地和远程服务器上运行code在Safari和Firefox。

I have run the code in Safari and Firefox both locally and on a remote server.

当放入浏览器的URL会返回一个字符串,并给了200一个状态code。

The URL when put into a browser will return the string and give a status code of 200.

我写了类似的code相同的URL在Mac控件,它运行良好,但同样的code在浏览器不会返回一个结果。

I wrote similar code to the same URL in a Mac Widget which runs fine, but the same code in a browser never returns a result.

推荐答案

是您的域 http://api.xxx.com/ 部分?如果没有,你被封锁的同源策略

Is http://api.xxx.com/ part of your domain? If not, you are being blocked by the same origin policy.

您可能想看看下面的堆栈溢出后的几个可能的解决方法:

You may want to check out the following Stack Overflow post for a few possible workarounds:

这篇关于从XMLHtt prequest空的responseText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 13:04