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

查看:39
本文介绍了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.

我想一种方法是做类似的事情

I suppose one way would be to do something like

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?

推荐答案

您可以使用 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 将在提交按钮被按下时发送.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天全站免登陆