简体   繁体   中英

How do I get my button to submit an AJAX form?

<%= link_to_remote "<span class='button_sprite_star'></span>Save Changes",
    "unsaved_changes = false; $('edit_content').submit();",
    :class=>"save action_button" %>

I'm using remote_form_for (the form works when I click the submit_tag in the form).

The reason why I want to have a different sumbit button, is because of how I'm doing the style of the page. The control buttons are outside the scope of the form.

I know my above method works for regular form_for's, but when the form is a remote_form_for I get this back:

try {
unsaved_changes = false;
Element.update("content_name_361", "Basic Agressive Pool Theory");
enablePreviewLink();
completeSave();
} catch (e) { alert('RJS error:\n\n' + e.toString()); alert('unsaved_changes = false;\nElement.update(\"content_name_361\", \"Basic Agressive Pool Theory\");\nenablePreviewLink();\ncompleteSave();'); throw e }

which is an AJAX response... but why is that getting sent to a new page instead of the page I was already on?

I'm using ruby 1.8.7 and rails 2.3.8

Solved by making it call this function instead of calling the form's submit:

ajax_sumbit = function(e){ // e is a jquery object of the form
    $j.ajax({
      type: "POST",
      url: e.attr("action"),
      data: e.serialize()
    });
  }  
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM