POST 请求 (Javascript) [英] POST Request (Javascript)

查看:18
本文介绍了POST 请求 (Javascript)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在不使用表单且不回发的情况下在 Javascript 中发出简单的 POST 请求?

How do you make a simple POST request in Javascript without using a forms and without posting back?

推荐答案

虽然我从@sundeep 答案中提取了代码示例,但为了完整起见,将代码张贴在此处

Though I am taking the code sample from @sundeep answer, but posting the code here for completeness

var url = "sample-url.php";
var params = "lorem=ipsum&name=alpha";
var xhr = new XMLHttpRequest();
xhr.open("POST", url, true);

//Send the proper header information along with the request
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

xhr.send(params);

这篇关于POST 请求 (Javascript)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆