我正在尝试使用AJAX登录Google帐户以请求Picassa网络照片。这就是代码:
xmlhttp=new XMLHttpRequest();
xmlhttp.open("POST","https://www.google.com/accounts/Login",true);
xmlhttp.send("accountType=HOSTED_OR_GOOGLE&Email=...&Passwd=...&service=lh2&source=prova");
document.getElementById('prova').innerHTML=xmlhttp.responseText;
这个firebug在Net选项卡中显示200 OK状态,但在Console中显示无法解释的错误。当然,没有任何内容出现在被称为“prova”的div中,因为答案是空的。
我也尝试添加此标题:
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
但是随后firebug在Net标签中显示400 Bad Request。你能帮助我吗?谢谢。
答案 0 :(得分:0)
你应该能够在firebug中查看ajax响应并查看发布给你的gtting - 你可以得到200错误,但在帖子中仍然会收到错误。您是否也需要使用AuthToken做某事?
答案 1 :(得分:0)
解决!出于安全原因,Firefox和新浏览器不允许对第三方应用程序进行AJAX调用。这里解释了所有内容:http://www.xml.com/pub/a/2005/11/09/fixing-ajax-xmlhttprequest-considered-harmful.html
答案 2 :(得分:0)
不确定我们是否获得了authToken ......
以下是我一直在制作xDomain帖子:
它需要一个名为flyJSONP的小库(微小),它使用YQL(Yahoo! Query Language)作为JSONP hack。效果很好,但无法发帖/获取标题。之后,我将数据发送到php,然后使用必要的标题创建跨域帖子。
FlyJSONP也适用于get ... FlyJSONP.get({...
FlyJSONP.post({
url: "https://www.google.com/accounts/ClientLogin",
parameters: {
name: "value"
},
success: function(data) {
console.log("the response is: " + data);
},
error: function(errorMsg) {
console.log(errorMsg);
},
complete: function(data){
console.log("...completed post!");
}
});