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

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!

图片转代码服务由CSDN问答提供 功能建议

我正在编写一个比较两个密码的东西,如果它们匹配,那么脚本会发出一个响应 它是一样的。

我目前有这个代码:

  $(“#repeatPw”)。keyup(function()  {
 jQuery.ajax({
 url:“System / Javascript / Functions / checkPasswords.php”,
 data:“'password1'='”+ $(“#Password”)。val()+“'  ,'password2'='“+ $(”#repeatPw“)。val()+”'“,
类型:”POST“,
成功:函数(数据){
 $(”#passwordMatch“)  .html(数据); 
},
错误:函数(数据){} 
}); 
}); 
   
 
 

现在我的问题 是我无法将这个密码1和密码2放在一个正确的数组中,我可以在checkPasswords.php中爆炸,这发布了这个:

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

但这不是一个合适的数组,因为它只将密码1置于正确的数组格式中,如何处理 我是否也以这种格式制作密码2?

提前谢谢大家!

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

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) {}
      });
    });
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • douge7771 2017-07-05 10:00

    Create an array and pass it as the ajax post data,

       var data=[];
    
        data['password1']= $("#Password").val();
        data['password2']= $("#repeatPw").val();
    

    Though you could do this in the client side itself.

    if($("#Password").val().trim() == $("#repeatPw").val().trim())
        //password Matches
    
    评论
    解决 无用
    打赏 举报
  • dtjxhf595733 2017-07-05 10:01

    Hopes this help u..

    $("#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) {}
      });
    });
    
    评论
    解决 无用
    打赏 举报
  • douyi2664 2017-07-05 10:01

    Try like this

    $("#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) {}
    });
     });
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题