testwishluck
2012-Feb-21 17:44 UTC
How to call javascript method from controller or by Ajax?
Hi guys, In Rails framework, I need to call the lightbox to add payment method by using javascript method AuthorizeNetPopup.openAddPaymentPopup(). But based on the design, the popup should be triggered by other ways not by clicking the normal button. For example, users click "signup" button, the server side can generate ProfileID, Token, and send the Token to page, but right now how can I automatically tirgger the AuthorizeNetPopup.openAddPaymentPopup() method to open the popup? If I can refer to Ajax, but how can I call the above method in .js file? I appreciate any idea or suggestion!!! Thank you very much in advance!!! Best! -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Robert Walker
2012-Feb-23 21:11 UTC
Re: How to call javascript method from controller or by Ajax?
testwishluck wrote in post #1048151:> Hi guys, > > In Rails framework, I need to call the lightbox to add payment method > by using javascript method AuthorizeNetPopup.openAddPaymentPopup(). > But based on the design, the popup should be triggered by other ways > not by clicking the normal button. > For example, users click "signup" button, the server side can generate > ProfileID, Token, and send the Token to page, but right now how can I > automatically tirgger the AuthorizeNetPopup.openAddPaymentPopup() > method to open the popup? > If I can refer to Ajax, but how can I call the above method in .js > file?There are many events that occur on a web page besides button/link click events. It''s all depends on when you want the popup to show. If you just need it to show when the page load then show the popup in the "document ready" event. Using JQuery: ----------------------- $(function() { // Show your popup here }); ----------------------- Note: The above is short for.. ----------------------- $(document).ready(function() { // Show your popup here }); ----------------------- If you want the popup to happen on some other event besides the DOM loaded event then you''ll need to bind your popup opening code to some other event. http://api.jquery.com/category/events/ As you''ll see there are quite a few different events you could potentially bind to. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
subbarao
2012-Feb-24 03:01 UTC
Re: Re: How to call javascript method from controller or by Ajax?
On 02/24/2012 02:41 AM, Robert Walker wrote:> testwishluck wrote in post #1048151: >> Hi guys, >> >> In Rails framework, I need to call the lightbox to add payment method >> by using javascript method AuthorizeNetPopup.openAddPaymentPopup(). >> But based on the design, the popup should be triggered by other ways >> not by clicking the normal button. >> For example, users click "signup" button, the server side can generate >> ProfileID, Token, and send the Token to page, but right now how can I >> automatically tirgger the AuthorizeNetPopup.openAddPaymentPopup() >> method to open the popup? >> If I can refer to Ajax, but how can I call the above method in .js >> file? > There are many events that occur on a web page besides button/link click > events. It''s all depends on when you want the popup to show. > > If you just need it to show when the page load then show the popup in > the "document ready" event. > > Using JQuery: > ----------------------- > $(function() { > // Show your popup here > }); > ----------------------- > > Note: The above is short for.. > ----------------------- > $(document).ready(function() { > // Show your popup here > }); > ----------------------- > > If you want the popup to happen on some other event besides the DOM > loaded event then you''ll need to bind your popup opening code to some > other event. > > http://api.jquery.com/category/events/ > > As you''ll see there are quite a few different events you could > potentially bind to. >If your request is javascript ( JS ) or AJAX request, just use below code respond_to do format.html {} format.js { render :js => "my_js_function();" } end note:- your request should be js request. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Benjamin Iandavid Rodriguez
2012-Feb-24 03:53 UTC
Re: Re: How to call javascript method from controller or by Ajax?
you can simplify this by setting the respond_to at the top of your controller example: class SomeController < ApplicationController respond_to :html, :json, :js and then inside your actions you just pass the param to a respond_with: def some_action respond_with @some_var end 2012/2/23 subbarao <subbarao.kly-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>> On 02/24/2012 02:41 AM, Robert Walker wrote: > >> testwishluck wrote in post #1048151: >> >>> Hi guys, >>> >>> In Rails framework, I need to call the lightbox to add payment method >>> by using javascript method AuthorizeNetPopup.**openAddPaymentPopup(). >>> But based on the design, the popup should be triggered by other ways >>> not by clicking the normal button. >>> For example, users click "signup" button, the server side can generate >>> ProfileID, Token, and send the Token to page, but right now how can I >>> automatically tirgger the AuthorizeNetPopup.**openAddPaymentPopup() >>> method to open the popup? >>> If I can refer to Ajax, but how can I call the above method in .js >>> file? >>> >> There are many events that occur on a web page besides button/link click >> events. It''s all depends on when you want the popup to show. >> >> If you just need it to show when the page load then show the popup in >> the "document ready" event. >> >> Using JQuery: >> ----------------------- >> $(function() { >> // Show your popup here >> }); >> ----------------------- >> >> Note: The above is short for.. >> ----------------------- >> $(document).ready(function() { >> // Show your popup here >> }); >> ----------------------- >> >> If you want the popup to happen on some other event besides the DOM >> loaded event then you''ll need to bind your popup opening code to some >> other event. >> >> http://api.jquery.com/**category/events/<http://api.jquery.com/category/events/> >> >> As you''ll see there are quite a few different events you could >> potentially bind to. >> >> If your request is javascript ( JS ) or AJAX request, just use below code > > respond_to do > format.html {} > format.js { render :js => "my_js_function();" } > end > note:- your request should be js request. > > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk@googlegroups.**com<rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe@**googlegroups.com<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at http://groups.google.com/** > group/rubyonrails-talk?hl=en<http://groups.google.com/group/rubyonrails-talk?hl=en> > . > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.