有没有使用jQuery没有详细的逐场击穿提交表单的方式? [英] Is there a way using jQuery to submit a form without the elaborate field by field breakdown?

查看:82
本文介绍了有没有使用jQuery没有详细的逐场击穿提交表单的方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用jQuery对链接进行基于AJAX的页面重载 - 他们带来了载入中...格窗口,然后关闭它,当内容回报和加载内容。这完全按预期工作。

I'm using jQuery to perform AJAX based page reloads on links - they bring up the "Loading..." div window and then close it when the content returns and load the content. This works exactly as expected.

我有几个不同的形式在我的项目,我想提出用同样的方法 - 在提交弹出一个载入中...格窗口,然后关闭它,当内容回报。有没有办法做到这一点,而无需编写自定义函数为每个表单?我见过的样品需要你抢和连接code每个表单字段,并通过它的AJAX方法。一些形式中只有几个领域,其他有许多所以这将是一个麻烦的过程。我想它只是抓住各个领域的形式,并提交下的字段名。

I have several different forms in my project that I would like to submit using the same method - on submit bring up a "Loading..." div window and then close it when the content returns. Is there any way to do this without writing a custom function for each form? The samples I've seen require you to grab and encode each form field and pass it in the ajax method. Some forms only have a few fields, others have many so this would be a cumbersome process. I'd like it to just grab all fields in the form and submit them under the field names.

对此有何见解将大大AP preciated!

Any insight on this would be greatly appreciated!

推荐答案

它看起来像你正在寻找沿的 .serialize() 。它基本上是jQuery的效用函数为AJAX调用或GET查询字符串编码表单元素。

It looks like you're looking for something along the lines of .serialize(). It's basically jQuery's utility function for encoding form elements for an AJAX call or a GET query string.

使用,让你的东西,看起来像 myinput = someValue中和放大器; myotherinput = someothervalue 根据名称属性你的表单元素。你可以扔掉的进入无论叫你正在做对您的服务器,只要他们认识的格式(与类似JSON数据或标量的字符串,例如)。

Using that gets you something that looks like myinput=somevalue&myotherinput=someothervalue based on the name properties of your form elements. You can chuck that into whatever call you're making against your server, as long as they recognize the format (versus something like JSON data or a scalar string, for example).

这篇关于有没有使用jQuery没有详细的逐场击穿提交表单的方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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