gpt4 book ai didi

javascript - POST 请求(Javascript)

转载 作者:技术小花猫 更新时间:2023-10-29 12:04:47 25 4
gpt4 key购买 nike

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

最佳答案

虽然我是从@sundeep 的回答中获取代码示例,但为了完整起见还是将代码发布在这里

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);

关于javascript - POST 请求(Javascript),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/692196/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com