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 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器