jquery - How to (re)bind to submit button/form on .load(ed) form -


How to implement an incredible JS (using rail and jQuery) How to implement an issue during initial times (Re: Add a Button / After Form Load (ing) is a new material that contains a form.

I have set up a new 'Make New Item' form, which is an emerging item (when the user clicks on a click button)

sale_case / show / _requirments_new Html .haml:

  - form_for ([@sale_case, @sale_case_requirement]),: html = & gt; {: Id = & gt; 'Necess_form' ,: class = & gt; "Submit-ajax-ajax"}. F | ...% Button {: type = & gt; "Submit"} Save  

application.js:

  jQuery (document) .ready (function () {jQuery (". Submit-with- AJAX "). SubmitWithAjax ();} ... jQuery.ajaxSetup {{beforeSend: function (xhr) {xhr.setRequestHeader (" accept "," text / javascript ")}}) jQuery.fn.submitWithAjax = function ( ) () This {sobit (function () {jQuery.post (this.action, jQuery (this). Serialize (), blank, "script"); Return;;) return;};};  

requirements_controller.rb:

def make @sale_case_requirement = @ sale_case.requirements.new (params [: requirement]) if @ sale_case_requirement.save @message = "Success .. .." @success = true # ... response_to do | Format | Format.js end end

Requirements / create.js.erb:

  mesg ("& lt;% = @ message% & gt;") ; & Lt;% - If the @ success% & gt; JQuery ("#cut_form") [0]. Reset (); JQuery ('# Requirements'). Load ('& lt;% = requirements_view_sale_case_requirements_path (@sale_c Ase.id)%>;); & Lt;% end% & gt;  

This is the first to work incredibly well around. The problem occurs when the user creates another object (on the form loaded through AJAX) button submitWithAjax is not bound to the function when you do so. (Ing) material?

I was finished in partial work to do this (intrusion), but it is not able to bug me, get the solution out of it. :

 % button {: type = & gt; "Submit",: onclick => "JQuery.post ('# sale_case_requirements_path (@ sale_case.id, @ sale_case_requirement.id)}', jQuery ('# need_form'). Serialize (), blank, 'script'); return false;" save the requirement " / Code>   

Based on the input of the input, the code has finished changing its version of code I found an error in finding 'submitWithAjax', but he told me in the right direction and after reading me .live documentation I came up with that which works:

application.js

  jquery (docum Ent) .ready (function () {# Just place it in jQuery (". Submit-with-ajax") Live ('submit', function () {JQuery.post (this.action, jquery (this) Serialize (), blank, "script"); return;}); ...}  

change the sale_case / show / _requirments_new button back to an unbearable% button {: type = & Quot; Submit & quot;} save required

thanks! / P>


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -