开发者

jQuery: How to distinguish the form being submitted inside the success callback function of $.post call?

开发者 https://www.devze.com 2023-03-25 15:41 出处:网络
I have the following jQuery code: $(\".save_button\").click(function() { var $form = $(this).closest(\"div.info_section\").find(\"form\");

I have the following jQuery code:

  $(".save_button").click(function() {
    var $form = $(this).closest("div.info_section").find("form");
    url = $form.attr("action");
    $.post(url, $form.serialize(), 
      function() {
        // need to figure out a way to distinguish the form being saved
      }
    );
  });

I have three forms (on the same page) that are tied to this function. The success callback function of $.post requires a way to distinguish which form is being submitted. Please advise 开发者_如何转开发how I would do so. Thanks.


You could use the $form variable inside the success callback:

$.post(url, $form.serialize(), function() {
    // $form could be used here to access the form element
    // whose contents was serialized and sent in the AJAX request
});
0

精彩评论

暂无评论...
验证码 换一张
取 消