我正在使用javascript發佈圖像到picasa。我有必要的令牌。但是,當我發佈,我得到一個錯誤「204沒有內容」使用Javascript發佈圖像到Picasa XMLHttpRequest
這是我的代碼。
function send()
{
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function()
{
if(xhr.readyState == 4)
alert(xhr.status);
}
xhr.open("POST","https://picasaweb.google.com/data/feed/api/user/default/albumid/default", true);
var type = document.getElementById('file').files[0].type;
xhr.setRequestHeader('Accept','message/x-jl-formresult');
xhr.setRequestHeader("content-type",type);
xhr.setRequestHeader('Content-Length',document.getElementById('file').files[0].size);
xhr.sendAsBinary(document.getElementById('file').files[0].getAsBinary());
}
如果您嘗試從除picasaweb.google.com之外的其他域執行該請求,[相同來源策略](http://en.wikipedia.org/wiki/Same_origin_policy)將阻止您。 – HoLyVieR
但他得到204迴應,所以不能成爲問題? –
只是挑剔:「204沒有內容」不是一個錯誤。 2xx類是爲成功代碼。引用RFC,204的意思是「服務器已經完成了請求,但不需要返回實體主體,並且可能想要返回更新後的元信息。響應可以包括以實體頭的形式的新的或更新的元信息,其中如果存在,應該與請求的變體相關聯。「 http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html –