Targeting multiple forms to send via ajax (jquery)

前端 未结 5 712
暖寄归人
暖寄归人 2020-12-03 16:17

I have multiple forms on my page. When I click the forms submit button, I want to send the form value of only that form through ajax. Here is what I have. The first form w

5条回答
  •  爱一瞬间的悲伤
    2020-12-03 17:02

    First, use class in your submit buttons. Be aware that ids are unique (by w3c specs)

    Then in your onclick listener, get the form using closest (same as parent but targeting a specific parent; in this case it is the form element). Here is the working code:

     

提交回复
热议问题