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 cplex运行后参数报错是为什么
  • ¥15 之前不小心删了pycharm的文件,后面重新安装之后软件打不开了
  • ¥15 vue3获取动态宽度,刷新后动态宽度值为0
  • ¥15 升腾威讯云桌面V2.0.0摄像头问题
  • ¥15 关于Python的会计设计
  • ¥15 聚类分析 设计k-均值算法分类器,对一组二维模式向量进行分类。
  • ¥15 stm32c8t6工程,使用hal库
  • ¥15 找能接spark如图片的,可议价
  • ¥15 关于#单片机#的问题,请各位专家解答!
  • ¥15 博通raid 的写入速度很高也很低