使用ajax将表单字段的特定部分发送到服务器? [英] send specific part of the form fields to server using ajax?

查看:95
本文介绍了使用ajax将表单字段的特定部分发送到服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

应用程序包含不同的部分,在不同的部分中具有许多表单字段.
我必须使用ajax分别更新每个部分..如何使用ajax提交特定部分的字段?
这里所有部分都以一种形式存在..
如下.

<form>  
 Section A:   
  <some fields>  
   Section B:   
 <some fields>  
 .......   
</form>

如果我使用Ajax提交表单,它将发送所有表单字段.但是我要立即保存特定部分..
任何实现此要求的方式??
在此先感谢.

解决方案

您已经说过,您可以使用Ajax提交整个表单,因此我假设您在编写$.ajax()时不需要帮助. (或$.post()或其他)本身,您只需要了解如何从某些字段中获取值即可.

您可以使用多种形式,每组一种-对我来说,这似乎是最简单的方法,尽管如果您还需要一次提交所有字段(可能允许使用JS的浏览器)将无法使用关闭).

或者您可以仅在特定部分的字段上使用 .serialize()方法.为这些字段提供一个将其标识为属于特定节的类,并使用$(".sectionClass1").serialize();或者将这些字段放入其他类型的容器(可能是<fieldset id="section1">)中,然后使用$("#section1 :input").serialize()进行选择.

Application contains different sections with many form fields in different sections.
I have to update the each section separately using ajax.. How to submit the specific section fields using ajax???
Here All the sections are in a single form..
As follows..

<form>  
 Section A:   
  <some fields>  
   Section B:   
 <some fields>  
 .......   
</form>

If i submit form using ajax, It is sending all form fields.. But i'm saving specific section at once..
Any way to implement this requirement???
Thanks in Advance..

解决方案

You've stated that you are able to submit the whole form with Ajax, therefore I'll assume you don't need help with writing the $.ajax() (or $.post() or whatever) itself, you just need to know about how to get the values from certain fields.

You can use multiple forms, one per group - to me this seems like the easiest way, though it won't work if you also need to be able to submit all the fields at once (perhaps to allow for browsers with JS turned off).

Or you can use the .serialize() method on just the fields of a particular section. Either give the fields a class that identifies them as belonging to a particular section and use $(".sectionClass1").serialize() or put the fields in some other sort of container, perhaps a <fieldset id="section1">, and select accordingly with $("#section1 :input").serialize().

这篇关于使用ajax将表单字段的特定部分发送到服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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