javascript - SweetAlert 2 通过 Ajax 请求传递值不起作用

标签 javascript ajax sweetalert2

我是 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/

相关文章:

javascript - 使用复选框将 JSON 结果解析为对象

javascript - jQuery setInterval 不循环

php - 我的 JavaScript 代码无法读取由我的 PHP 代码生成的 JSON。怎么了?

javascript - 隐藏与 css vs JS 创建元素 vs ajax

php - 访问另一页面后保留浏览器滚动位置

javascript - 我怎样才能获得甜蜜警报弹出消息内容的值(value)?

reactjs - 使用 Sweet Alert 2 获取 this.props 在使用警告警报后未定义

javascript - "this."对象引用 : Can't access model in onInit 范围的问题

Javascript:检查字符串中匹配的关键字数组

javascript - sweetalert2 消失后重定向到页面