在发布之前使用jQuery修改POST变量 [英] Modify POST vars before post, using jQuery
问题描述
当用户提交表单时,我想修改(添加)POST请求的一些参数,在它从客户端发送到服务器之前。
即
- 用户点击'提交'
- 我的jQuery提交hander开始执行...
- 我创建了一些新的键/值对并将它们添加到POST有效载荷
目前看起来我唯一的选择是使用 感谢您的帮助。 编辑:我已经将提交处理程序附加到形成;我试图在用户点击提交按钮和发送到服务器的请求之间编辑post vars。 使用表单上的 等。 I have a form, and a submit handler in jQuery. When the user submits the form, I want to modify (add) some parameters to the POST request, before it is despatched from the client to the server. i.e. At the moment, it looks like my only options are to use Thanks for any help. Edit: I've already attached a submit handler to the form; I'm trying to edit the post vars in between the user clicking the submit button, and the request being sent to the server. Use the etc. 这篇关于在发布之前使用jQuery修改POST变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! $。post()
或 $('form')。append('& lt; input type =hiddenname = ... value = ...'); $ c
submit()
函数创建回调。如果函数返回true,表单将被提交;
$('#theForm')。submit(function(){
$(#field1).val(newValue1);
$(#field2).val(newValue2);
$(this).append(newFormField);
return true;
});
$.post()
, or $('form').append('<input type="hidden" name=... value=...');
submit()
function on the form to create a callback. If the function returns true, the form will be submitted; if false, the form will not post.$('#theForm').submit(function() {
$("#field1").val(newValue1);
$("#field2").val(newValue2);
$(this).append(newFormField);
return true;
});