我想向其他域名发送请求参数。
我已经知道跨脚本需要使用JsonP,我已经使用Jquery ajax使用了JsonP。
但是我不知道如何使用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);
}
}
}