Changing the data in before submit

瘦欲@ 提交于 2019-12-01 14:30:53

问题


I am using the ajaxForm plugin found here

Now i have a form with username & password

My requirement is to change the value of password field to its md5 so for that I am using the plugin found here

so for that I am using like this :

$('myForm').ajaxForm({

   url : 'pathtosend',
   type : 'post',
   beforeSubmit : function(arr, $form, options){
      $('#password').val($.md5($('#password').val()));
   },
   success : function(response, statusText, xhr, $form){
      alert('blah blah');
   }
});

Now when I print the value of password in java servlet code it shows the one that I passed and not the md5 of the value as I did.

When I changed the coding to the click of the submit button and manipulating the submit its done so my question is what is the significance of beforeSubmit when the data changed is not going to reflect in the submit


回答1:


You need to change your beforeSubmit function to this:

    beforeSubmit : function(arr, $form, options){
      arr.push({name:'hashed-password', value:$.md5($('#password').val())})
   },

Then you can access the hashed-password variable in your servlet.

The reason for this is that the value from the text input has already been processed by AjaxForm and stored in the arr array.

Edit: if you don't want to send the plaintext password, you can use your original method but change beforeSubmit : function(arr, $form, options){ to beforeSerialize : function() {



来源:https://stackoverflow.com/questions/13720766/changing-the-data-in-before-submit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!