我要發送的請求參數到其他域JavaScript的XMLHttpRequest的JSONP
我已經知道了跨腳本需要JSONP和我已經使用JSONP使用jQuery阿賈克斯
,但我不知道如何做跨作爲腳本使用XMLHttpRequest的
下面的代碼我的基本的XMLHttpRequest代碼。
我想我需要恰克xhr.setRequestHeader()
,我必須添加解析代碼
請給我任何的想法
var xhr;
function createXMLHttpRequest(){
if(window.AtiveXObject){
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}else{
xhr = new XMLHttpRequest();
}
var url = "http://www.helloword.com";
}
function openRequest(){
createXMLHttpRequest();
xhr.onreadystatechange = getdata;
xhr.open("POST",url,true);
xhr.setRequestHeader("Content-Type",'application/x-www-form-urlencoded');
xhr.send(data);
}
function getdata(){
if(xhr.readyState==4){
if(xhr.status==200){
var txt = xhr.responseText;
alert(txt);
}
}
}
的可能重複[途徑來規避同源策略(http://stackoverflow.com/questions/3076414/ways-to-circumvent-the-same-origin-policy) – Quentin
你可以用」使用JSONP進行POST請求。 JSONP不是唯一的製作跨域請求的方法。如果您需要製作交叉源POST請求,請使用JSONP以外的技術。 – Quentin
你的意思是如果我取得reqeusts,這是可能的? – happenask