jQuery的AJAX提交表单 [英] jQuery AJAX submit form

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

问题描述

我有名字orderproductForm和输入的不确定数量的一种形式。

I have a form with name orderproductForm and an undefined number of inputs.

我想要做一些jQuery.get或AJAX或类似的东西的,将通过Ajax调用一个页面,然后一起发送的形式orderproductForm的全部投入。

I want to do some kind of jQuery.get or ajax or anything like that that would call a page through Ajax, and send along all the inputs of the form orderproductForm.

我想一个办法是像做

jQuery.get("myurl",
          {action : document.orderproductForm.action.value,
           cartproductid : document.orderproductForm.cartproductid.value,
           productid : document.orderproductForm.productid.value,
           ...

不过,我不知道到底是所有的表单输入。是否有一个特点,功能或东西,只想把所有的表单输入?

However I do not know exactly all the form inputs. Is there a feature, function or something that would just send ALL the form inputs?

感谢

推荐答案

您可以使用当作ajaxForm / ajaxSubmit的功能从 Ajax表格插件或jQuery的序列化功能。

You can use the ajaxForm/ajaxSubmit functions from Ajax Form Plugin or the jQuery serialize function.

当作ajaxForm

$("#theForm").ajaxForm({url: 'server.php', type: 'post'})

$("#theForm").ajaxSubmit({url: 'server.php', type: 'post'})

当作ajaxForm将发送时提交按钮是pressed。 ajaxSubmit会立即发送。

ajaxForm will send when the submit button is pressed. ajaxSubmit sends immediately.

序列化

$.get('server.php?' + $('#theForm').serialize())

$.post('server.php', $('#theForm').serialize())

AJAX序列化文档这里

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

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