Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/384.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用post方法加载位置_Javascript_Ajax - Fatal编程技术网

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', 功能响应、状态{ //成功 }, 函数误差{ //错误' } ;