【问题标题】:jquery form not gettin submittedjquery表单没有被提交
【发布时间】:2016-12-26 13:25:16
【问题描述】:

这是我编写的脚本,用于在验证后提交表单并使用 $_POST 接收 php 文件中的值,但我没有在 php 文件中获取值。当我尝试回显该值时,它在 php 中显示为空白。请指导我,我是 jquery 的新手

<script>
$("#changepassform").validate({


  rules: {
    old_password: "required",
    password: "required",
    password2: {
      equalTo: "#password"
    },
  },
  messages: {

    old_password: "Please enter old password",

    password: "Please enter new password",
    password2: " Enter Confirm Password Same as Password"

  },
  submitHandler: function(form) {

      var current_password = $("#current_password").val();
      var new_password = $("#password").val();
      var comfirm_password = $("#password2").val();
      var id = $("#id").val();
      var dataString = 'newpassword1=' + new_password + '&id1=' + id;

      $.ajax({
        type: "POST",
        url: "changepassword.php",
        data: "dataString",
        success: function(response) {

          $("#status").html(response);
        }
      });

    }
    //form.submit();

  //return false;  

});
// required to block normal submit since you used ajax
//form.submit();
</script>

【问题讨论】:

  • 将数据:“dataString”更改为数据:dataString,
  • 而不是 data: "dataString", 更新 data: dataString, 并尝试解析表单。
  • 谢谢我的朋友 prakash,但不引用 dataString 背后的原因是什么......我们将不胜感激
  • 当你使用引号时,它被认为是字符串。但是你传递了一个变量
  • @Hemant,dataString 是变量,并且在该变量中您已经分配了字符串。因此,无需引用该变量。

标签: php jquery html


【解决方案1】:

发送数据时出错..

<script>
    $("#changepassform").validate({


      rules: {
        old_password: "required",
        password: "required",
        password2: {
          equalTo: "#password"
        },
      },
      messages: {

        old_password: "Please enter old password",

        password: "Please enter new password",
        password2: " Enter Confirm Password Same as Password"

      },
      submitHandler: function(form) {

          var current_password = $("#current_password").val();
          var new_password = $("#password").val();
          var comfirm_password = $("#password2").val();
          var id = $("#id").val();
          var dataString = 'newpassword1=' + new_password + '&id1=' + id;

          $.ajax({
            type: "POST",
            url: "changepassword.php",
            data: dataString,
            success: function(response) {

              $("#status").html(response);
            }
          });

        }
        //form.submit();

      //return false;  

    });
    // required to block normal submit since you used ajax
    //form.submit();
    </script>

使用serialize() 方法。在发出AJAX 请求时,可以在URL 查询字符串中使用序列化值。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-16
    • 2011-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-15
    相关资源
    最近更新 更多