【问题标题】:xhr sending requests to specific port?xhr 向特定端口发送请求?
【发布时间】:2013-08-03 15:58:28
【问题描述】:

我是 ajax 开发的新手,我正在尝试使用 xhr 来获取和发布数据,问题是当我使用基于端口的请求时?

这是我的工作代码,而不是工作代码

$.ajax({
url : "login.php",
type : "post",
data : {
    userProfile : JSON.stringify(data)
},
success : handleDBResponse,

    error : function(jqXHR, textStatus,errorThrown) {

    console.log("The following error occured: "+ textStatus,errorThrown);
},
complete : function() {
    // console.log("user authentication
    // successful.")
}
});

这很好用,但是当我使用带有 url:port 的原生 xhr 时没有响应。

 function reqListener () {
 console.log(this.responseText);
    };

      var oReq = new XMLHttpRequest();
      oReq.onload = reqListener;
      oReq.open("get", "http://www.domain.com:443/akorp.css", true);
      oReq.send();

它不起作用,我被调试了,我发现请求状态被取消了。

.htaccess 包含文件

Access-Control-Allow-Origin:*

我仍然收到错误

www.domain.com:443 not allowed by www.domain.com Access-Control-Allow-Origin etc..

此错误的可能原因是什么以及如何正确地将请求发送到端口?

【问题讨论】:

    标签: ajax html jquery xmlhttprequest cors


    【解决方案1】:

    443 是 HTTPS 端口。也许您应该尝试使用 HTTPS URL 而不是强制使用端口。

    我不确定我想知道您为什么要使用 xhr 从其他人的 serer 中提取 CSS 文件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-14
      • 1970-01-01
      相关资源
      最近更新 更多