微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Sweetalert 使用 ajax 和 php 提交 inputValue

如何解决Sweetalert 使用 ajax 和 php 提交 inputValue

我有一个允许用户输入 pin 的 Sweetalert 模式。 我也验证了它,但任何时候我都尝试将数据发送到 PHP 页面页面不会获取数据。这是我的代码示例。

索引页

<script>
  $(document).ready(function(){ 
    swal({
  title: "Setup Transaction pin",text: "Enter a memorable 4digit pin to keep your account safe and make sure every transactions comes from you.",type: "input",showCancelButton: false,cloSEOnConfirm: false,animation: "slide-from-top",inputType: "number",inputPlaceholder: "Enter a pin"
},function(inputValue){
  if (inputValue === null){
    swal.showInputError("Please enter a pin!");
    return false
  }
  if (inputValue === "") {
    swal.showInputError("Please enter a pin!");
    return false
  }
  
  if (inputValue.length !== 4) {
    swal.showInputError("Pin must be 4digits!");
    return false
  }
  var pin = inputValue.toString();
     $.ajax({
        url: './backend/edit-profile?action=register_pin',type: 'POST',data: {
                    pin: pin
        },dataType: "json",cache: false,contentType: false,processData: false,success : function(data){
          if (data.code == "200"){
             swal({
                                            title: data.msg,//text: data.msg+inputValue" \n",type: "success",});
          } else {
            swal({
                                            title: data.msg,// text: data.msg+" \n",type: "error",});
          }
        }
      });
//   swal("Nice!","You wrote: " + inputValue,"success");
});
  });
</script>

PHP 代码

<?PHP
if($action == "register_pin"){
   $pin = $_POST['pin']);
   if(empty($pin) || strlen($pin) !== 4){
       $data['msg'] = "Enter a pin $pin";
   }else{
   
        $data['code'] = 200;
        $data['msg'] = "You entered $pin";
    
   }    
}

?>

除了值之外,一切正常。 PHP 代码与 inputValue 相呼应

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。