send specific part of the form fields to server us

2019-07-15 11:37发布

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..

2条回答
forever°为你锁心
2楼-- · 2019-07-15 11:48

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().

查看更多
手持菜刀,她持情操
3楼-- · 2019-07-15 11:54

Couple of ways that I can suggest

  • Use Dom selector to separate out form fields and then serialize the values.

  • Use multiple forms to serialize the form values.

Example Gist of multi form

Then you could use regular JQuery to serialize and submit values

$("#form1").serialize()
$("#form2").serialize()
查看更多
登录 后发表回答