Javascript Post Body?

时间:2016-09-24 07:48:33

标签: javascript jquery post xmlhttprequest

我试图通过xmlhttprequest或jquery ajax在跨服务器上发送文件,两者似乎都将文件发送到我的开发服务器,我有一个PHP将比特流保存为docx格式。

问题是当我将它发送到myclients服务器时,它们会获得0bytes。奇怪的是...当我使用邮递员发送文件时,它完美地运作。 下面是我读取和发送文件的代码。



var xhr = new XMLHttpRequest();
xhr.open('GET', my_file, true);
xhr.setRequestHeader("cache-control", "no-cache");
xhr.responseType = 'blob';

xhr.onload = function(e) {
  if (this.status == 200) {
    // get binary data as a response
    var blob = this.response;
    var resume = new XMLHttpRequest();
    resume.open('POST', client_api, true);
    resume.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    resume.send(blob);

  }
};
xhr.send();




我也可以获取发送到我服务器的数据。我的客户端开发人员说的是我需要在POST BODY中发送数据流...此时让我完全感到困惑。

请帮忙。 提前谢谢。

1 个答案:

答案 0 :(得分:0)

我认为您正面临某种跨域限制。邮差可以访问任何域名。

了解有关Chrome如何处理跨源请求的更多here

Related question

相关问题