使用iframe:无法执行'发送' on' XMLHttpRequest'

时间:2016-06-14 12:26:10

标签: javascript django iframe xmlhttprequest

我在我的网站上使用Django 1.6和Apache,一开始我的网站工作正常,但当我把它放在iframe中时,它出现在控制台中:

  

Uncaught NetworkError:无法执行'发送' on' XMLHttpRequest':无法加载' http://www.example.com'

我的iframe看起来像这样,很简单:

    <iframe src="http://www.example.com" width="700" 
      height="400" sandbox="allow-forms allow-scripts" style="border: 1px></iframe>

发生此错误的javascript部分是:

getData: function (url, params, method, cb, async) {
    if (async == "undefined") var async = true;
    if (params)  var par = JSON.stringify(params);
    if (window.XMLHttpRequest) {
      xmlhttp = new XMLHttpRequest();   
      if (xmlhttp.overrideMimeType) {
          xmlhttp.overrideMimeType("text/xml");
        }
    } else if (window.ActiveXObject) {
        try {
          xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch(e) {
            try {
                xmlhttp = new ActivetXObject("Microsoft.XMLHTTP");
            } catch(e2) {}
        }
    }
    if (!xmlhttp) {
        return cb();
    }
    xmlhttp.open(method, url, async);
    xmlhttp.setRequestHeader("Content-type", "application/json");

    /**
     * Description
     * @method onreadystatechange
     * @return 
     */
    xmlhttp.onreadystatechange = function() {
      if (xmlhttp.readyState == 4) {
        cb(xmlhttp.responseText);
      }
    }
    if (params)  xmlhttp.send(par);
    else     xmlhttp.send();
  },

我已经在X_FRAME_OPTIONS = 'ALLOWALL'中设置了settings.py并运行了chromium-browser --disable-web-security命令,但仍无效。但是,在浏览器控制台网络部分中,XHR请求的状态为200。我已经谷歌了很长时间但没有找到解决方案,希望你能得到一些建议。谢谢。

PS:这是我的网络控制台:

Response Headers
HTTP/1.0 200 OK
Date: Tue, 14 Jun 2016 14:00:45 GMT
Server: WSGIServer/0.1 Python/2.7.6
X-Frame-Options: ALLOWALL
Content-Type: text/html; charset=utf-8
Access-Control-Allow-Origin: null
Access-Control-Allow-Credentials: true

0 个答案:

没有答案