我是 js 编程新手。
目前,我正在尝试将甜食弹出窗口的值传递给我的 PHP 查询。但它不起作用。(如果我按下确认按钮,表格将被关闭并且没有任何反应)。 这是我的js代码。
function ChangePassword(){
swal({
title: 'Kennwort ändern',
html:
'<input id="swal-input1" placeholder ="altes Kennwort" class="swal2-input">' +
'<input id="swal-input2" placeholder ="neues Kennwort" class="swal2-input">' +
'<input id="swal-input3" placeholder ="Kennwort wiederholen" class="swal2-input">',
focusConfirm: false
}) .then(function(isConfirm) {
$.ajax({
type: 'POST',
url: 'ChangePassword.php',
data: {
'pw_old': document.getElementById('swal-input1').value,
'pw_new': document.getElementById('swal-input1').value,
'pw_newconf': document.getElementById('swal-input1').value
},
success: function(result) {
swal({
title: result,
type: "success"}
);
},
})
})
谁能告诉我我的错误在哪里?
最佳答案
您输入的 ID 有误。
正确代码如下:
函数更改密码(){
swal({
title: 'Kennwort ändern',
html:
'<input id="swal-input1" placeholder ="altes Kennwort" class="swal2-input">' +
'<input id="swal-input2" placeholder ="neues Kennwort" class="swal2-input">' +
'<input id="swal-input3" placeholder ="Kennwort wiederholen" class="swal2-input">',
focusConfirm: false
}) .then(function(isConfirm) {
$.ajax({
type: 'POST',
url: 'ChangePassword.php',
data: {
pw_old: document.getElementById('swal-input1').value,
pw_new: document.getElementById('swal-input2').value,
pw_newconf: document.getElementById('swal-input3').value
},
success: function(result) {
swal({
title: result,
type: "success"}
);
},
})
})
}
希望能解决你的问题
关于javascript - SweetAlert 2 通过 Ajax 请求传递值不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53449923/