gpt4 book ai didi

javascript - 直接从 JS 提交 PHP 表单(无 HTML)

转载 作者:行者123 更新时间:2023-11-30 15:08:24 24 4
gpt4 key购买 nike

我正在尝试通过 JS 发送表单,而不需要 HTML,我有一个包含用户信息的表格,并且有使用 JS 自动添加的按钮,我无法将该信息传递给 HTML(JS表会覆盖 HTML 表并删除所有表单),有没有一种方法可以仅使用 JS 向 PHP 提交查询?

这是我点击 JS 创建的按钮时运行的函数

function banAccount(id, username){
swal({
title: "Do you really want to ban "+username+"?",
text: "Enter amount of days, -1 equals to permanent ban.",
input: 'number',
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes",
showLoaderOnConfirm: true,
preConfirm: function (duration) {
return new Promise(function (resolve, reject) {
setTimeout(function() {
if (duration === '0') {
reject('Please type -1 for permanent ban or a number greater than 1!')
} else {
resolve()
}
}, 2000)
})
},
allowOutsideClick: false
}).then(function(duration){
action_id = id;
action_type = "ban";
action_params = duration;
alert("id:"+action_id+", type:"+action_type+", params:"+action_params)
// Here's where I need to send "action_id", "action_type" and "action_params" to PHP
});
}

最佳答案

你需要使用ajax。

$.ajax ({
url: "PHP-PAGE-TO-POST-TO.php",
data: { action_id : action_id,
action_type : action_type,
action_params : action_params },
success: function( result ) {
alert("Hi, testing");
alert( result );
//the variable "result" holds any value the PHP script outputs
}
});

关于javascript - 直接从 JS 提交 PHP 表单(无 HTML),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45419188/

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