Javascript 使用post方法加载位置
通常我们使用Javascript 使用post方法加载位置,javascript,ajax,Javascript,Ajax,通常我们使用 window.location.href="/index.php?querystring"; 在javascript中。有没有一种方法可以在文档中没有任何表单的情况下通过post方法发送查询字符串?您需要使用XMLHttpRequest来完成此操作 演示: 脚本: 函数发布url、数据、成功、错误{ var ajax=new window.XMLHttpRequest; ajax.onreadystatechange=函数{ 如果ajax.readyState==4{//响应就绪
window.location.href="/index.php?querystring";
在javascript中。有没有一种方法可以在文档中没有任何表单的情况下通过post方法发送查询字符串?您需要使用XMLHttpRequest来完成此操作
演示:
脚本:
函数发布url、数据、成功、错误{
var ajax=new window.XMLHttpRequest;
ajax.onreadystatechange=函数{
如果ajax.readyState==4{//响应就绪
如果ajax.status==200{//success
如果成功,则为ajax.responseText、ajax.statusText;
}否则{
如果错误为ajax.statusText;
};
};
};
ajax.open'POST',url;
发送数据;
};
post'/index.php',querystring',
功能响应、状态{
//成功
},
函数误差{
//错误'
}
;