提交前更改数据

编程入门 行业动态 更新时间:2024-10-23 21:25:42
本文介绍了提交前更改数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用此处

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

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

更多推荐

提交前更改数据

本文发布于:2023-10-16 00:30:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1495940.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!