提交前更改数据 [英] Changing the data in before submit

查看:89
本文介绍了提交前更改数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此处

现在我有一个表单,其中用户名& 密码

Now i have a form with username & password

我的要求是将密码字段的值更改为其 md5 ,为此,我使用的是

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');
   }
});

现在,当我在 java servlet代码中打印 password 的值时,它显示的是我传递的值,而不是我的值的md5.

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.

当我将编码更改为单击 submit 按钮并操纵提交完成时,我的问题是,当数据更改时 beforeSubmit 的意义是什么?不会提交

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

推荐答案

您需要将beforeSubmit函数更改为此:

You need to change your beforeSubmit function to this:

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

然后,您可以在servlet中访问hashed-password变量.

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

这样做的原因是来自文本输入的值已经由AjaxForm处理并存储在arr数组中.

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

如果您不想发送纯文本密码,则可以使用原始方法,但可以将beforeSubmit : function(arr, $form, options){更改为beforeSerialize : function() {

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() {

这篇关于提交前更改数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆