我想知道是否有办法做到这一点:
<form action="http[://localhost/.../script.php" method="POST">
常规通话。我不希望它在表单提交时运行,但我不希望它在调用函数时运行。
我会使用 jQuery 还是 AJAX?
最佳答案
您可以使用Fetch API在 chrome 上这样做:
// building your form values
var data = new URLSearchParams();
data.set('var1', 'value 1');
data.set('var2', 'value 2');
// send to the endpoint
fetch("http://localhost/.../script.php", {
method: 'POST',
mode: 'no-cors',
cache: 'no-cache',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: data
}).then(function(response) {
// check the response object for result
// ...
});
关于javascript - 如何在 Chrome 扩展中使用 javascript 发出 POST 请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58020712/