使用jQuery发布表单值的简单方法 [英] Easy way to post form values using jQuery
问题描述
我有一个简单的表单,我希望以简单的方式回发到服务器并获得结果。我在后端使用自定义ISAPI插件,因此使用JSON或其他时髦的东西不是一种选择。如何才能做到这一点?
编辑:如果可能的话,我宁愿不使用外部插件
使用 如果您在页面上有多个表单,您可以在按钮上单击此代码以获取正确的表单Id(其中'someButton'可以是任何有效的jQuery选择器): I have a simple form that I wish to postback to the server in an easy fashion and get the result. I am using a custom ISAPI plugin on the backend so using JSON or other funky stuff isn't an option. How best can I do this? Edit: I would also rather not use external plugins, if possible Use Very simple example (from jQuery's website using PHP, but any URL would do): If you have multiple forms on the page you can use this code on button click to get the correct form Id (where 'someButton' can be any valid jQuery selector):
这篇关于使用jQuery发布表单值的简单方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! serialize
来获取表单的字符串表示,然后使用jQuery的
$。post(test.php,$(#testform)。serialize ));
$('someButton')。click(function() {
//旧,效率较低的代码
// var formId = $(this).closest(form)。attr(id);
// $。post test.php,$(#+ formId).serialize());
//根据Vincent Robert的建议,简化版本
$ .post(test.php ,$(this).closest(form)。serialize());
});
serialize
to get a string representation of your form and then simply post it using jQuery's post
AJAX function.$.post("test.php", $("#testform").serialize());
$('someButton').click(function() {
//old, less efficient code
//var formId = $(this).closest("form").attr("id");
//$.post("test.php", $("#" + formId).serialize());
//as per Vincent Robert's suggestion, simplified version
$.post("test.php", $(this).closest("form").serialize());
});