dsxon40042 2017-07-05 09:54
浏览 67
已采纳

Jquery Ajax Post输入数据数组

I am writing a thing to compare two passwords with each other, if they match the script sends out a response that says it is the same.

I currently have got this code:

$("#repeatPw").keyup(function(){
    jQuery.ajax({
        url: "System/Javascript/Functions/checkPasswords.php",
        data: "'password1'='" + $("#Password").val() + "', 'password2'='" + $("#repeatPw").val() + "'",
        type: "POST",
        success: function(data) {
            $("#passwordMatch").html(data);
        },
        error: function(data) {}
    });
});

Now my problem is that i cant get this password1 and password2 in a proper array i can explode in the checkPasswords.php, this posts this:

Array ( ['password1'] => 'fasfasdfasSD2', 'password2'='asdasdasd' )

But this is not a proper array as it only puts password1 in proper array format, how would i go about making password2 in this format too?

Thank you all in advance!

  • 写回答

4条回答 默认 最新

  • dongsuiying7773 2017-07-05 10:08
    关注

    You can do it with a FormData object:

    $("#repeatPw").keyup(function(){
      var fd = new FormData();
      fd.append('password1', $("#Password").val());
      fd.append('password2', $("#Password").val());
      jQuery.ajax({
        url: "System/Javascript/Functions/checkPasswords.php",
        data: fd,
        type: "POST",
          success: function(data) {
            $("#passwordMatch").html(data);
        },
        error: function(data) {}
      });
    });
    

    Or do it the JSON way:

    $("#repeatPw").keyup(function(){
      jQuery.ajax({
        url: "System/Javascript/Functions/checkPasswords.php",
        data :{
                password1: $("#Password").val(),
                password2: $("#repeatPw").val(),
                },
        type: "POST",
        success: function(data) {
            $("#passwordMatch").html(data);
        },
        error: function(data) {}
      });
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 GENESYS无法找到EESoft Flexnet Licence Serve
  • ¥15 流式socket文件传输答疑
  • ¥20 keepalive配置业务服务双机单活的方法。业务服务一定是要双机单活的方式
  • ¥50 关于多次提交POST数据后,无法获取到POST数据参数的问题
  • ¥15 win10,这种情况怎么办
  • ¥15 如何在配置使用Prettier的VSCode中通过Better Align插件来对齐等式?(相关搜索:格式化)
  • ¥100 在连接内网VPN时,如何同时保持互联网连接
  • ¥15 MATLAB中使用parfor,矩阵Removal的有效索引在parfor循环中受限制
  • ¥20 Win 10 LTSC 1809版本如何无损提升到20H1版本
  • ¥50 win10 LTSC 虚拟键盘不弹出