简体   繁体   English

跨子域请求

[英]Cross-subdomain request

I need to make a cross subdomain request. 我需要提出跨子域请求。 There is a classic asp site which create an XMLHttpRequest to my PL/SQL Oracle webpage. 有一个经典的ASP站点,可在我的PL / SQL Oracle网页上创建XMLHttpRequest

The asp site has the domain: test/site.asp and the PL/SQL webpage has the domain test:7779/site... so the top level domain is the same asp站点的域为:test / site.asp,而PL / SQL网页的域为test:7779 / site ...,因此顶级域是相同的

This is my XmlHttpRequest: 这是我的XmlHttpRequest:

var xmlHttp = null;
xmlHttp = new XMLHttpRequest();
xmlHttp.onload = function() {
    if (xmlHttp.readyState === 4) {
        if (xmlHttp.status === 200) {
            createChart(divID, xmlHttp.responseText, counter);
        } else {
            console.error("error");
        }
    } 
};

xmlHttp.open( "GET", theUrl);
xmlHttp.setRequestHeader( "pragma", "no-cache" );
xmlHttp.send( null );

No error occurs in IE11, but in Chrome: 在IE11中没有发生错误,但在Chrome中:

XMLHttpRequest cannot load http://test:7779/site
No 'Access-Control-Allow-Origin' header is present on the requested resource. 
Origin 'http://test' is therefore not allowed access.
The response had HTTP status code 501.

Is there a solution to make a cross subdomain request? 有没有提出跨子域请求的解决方案? Maybe with an iframe in my asp site, to get the content? 也许在我的ASP网站中使用iframe来获取内容?

UPDATE: 更新:

I know tried to set the document.domain at both sides to the same: test. 我知道尝试将document.domain都设置为相同:测试。 But this also didn't solved the problem. 但这还没有解决问题。

My suggestion is, why dont you use MSXML2.ServerXMLHTTP object, as you have Classic ASP in hand? 我的建议是,为什么您不使用MSXML2.ServerXMLHTTP对象,因为您手中有经典ASP? So that XMLHttp request will be sent from server to server and not from browser. 这样XMLHttp请求将在服务器之间而不是浏览器之间发送。

You can use it like this, 你可以这样使用

Dim xmlhttp
  Set xmlhttp = Server.CreateObject("MSXML2.ServerXMLHTTP")
  xmlhttp.setTimeouts 30,500,1000,1000
  xmlhttp.Open "GET", "http://yourlink" & time, false
  On Error Resume Next
  xmlhttp.Send
  If Err.Number Then
    getBBstatus = "Could Not Retrieve Data"
    Err.Clear
  Else
    getBBstatus = xmlhttp.ResponseText
   ' Do something with the response here
  End If
  On Error Goto 0
  Set xmlhttp = nothing

Hope it helps, thanks. 希望能有所帮助,谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM