2016-09-24 38 views
0

我想通過xmlhttprequest或jquery ajax通過跨服務器發送文件,兩者似乎都將文件發送到我的開發服務器,在那裏我有一個PHP將位流保存爲docx格式。Javascript Post Body?

問題是,當我發送到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中發送數據流......讓我完全糊塗在這一點上。

請幫忙。 在此先感謝。

回答

0

我認爲你正面臨某種跨域限制。郵差可以訪問任何域。

瞭解更多here關於Chrome如何處理跨源請求。

Related question