Your problem is in your jQuery call. You need to use the value returned by the server and update the DOM in your success call. Have a look at these tutorials:
http://wabism.com/ajax-tutorial-with-jquery/ http://viralpatel.net/blogs/2009/04/jquery-ajax-tutorial-example-ajax-jquery-development.html http://www.roseindia.net/ajax/jquery/ http://www.codingquery.com/30-ajax-tutorials-jquery-examples On Tue, May 29, 2012 at 11:59 AM, amruby <vgrkrish...@gmail.com> wrote: > > > On Thursday, 24 May 2012 08:32:42 UTC-4, azizmb.in wrote: >> >> Hi Vishnu >> >> Users on this group are not here to *give* you solutions, rather to >> point you in the correct direction. >> >> To point you in the correct direction, you need to respond to the js >> format<http://whoneedsactions.com/blog/2010/10/24/jquery-ajax-with-rails-respond-to-format-dot-js/>, >> and then update the number on your page in the success function of the ajax >> call. >> >> > > > > > > > > > > > > > > > > > > > >> >> On Thu, May 24, 2012 at 4:43 PM, amruby <vgrkrish...@gmail.com> wrote: >> >>> Hi >>> * *I think this is my 4 or 5th post about the ajax issues with my >>> rails code. But i couldn't rectify my issues sofar. >>> problem is, >>> >>> In my pages.html.erb have one text field and button. when i click on >>> that button, the text field value will get into the controller through >>> ajax,so after the function i need to get that value(textfield value) in >>> same page. >>> >>> *page.html.erb* >>> >>> <%= form_tag({:controller => 'bpages',:action => 'add' }, {:method => >>> :post}) do %> >>> >>> <%= text_field_tag('Bnum' ,nil, :id => "bnum") %> >>> <%= submit_tag "Add", :id => "addbtn", :class => "*addsubmit* btn >>> btn-large btn-success" %> >>> <%end%> >>> <div class="adddtl" >>> <strong><%= *@number*%></strong> added >>> </div> >>> >>> Here is my ajax part >>> >>> *header.js* >>> * >>> * >>> $(".*addsubmit*").click(**function() { >>> var bnum = $("#bnum").val(); >>> var dataString = 'bnumber='+ bnum; >>> >>> if(bnum=='' ) >>> { >>> $('.adderror').fadeIn(300).**show(); >>> $('.adderror').fadeOut(3000); >>> } >>> else >>> { >>> >>> $.ajax({ >>> type: "POST", >>> url: "http://localhost:3000/bpages/**add<http://localhost:3000/bpages/add> >>> ", >>> data: dataString, >>> success: function(){ >>> >>> $('.adddtl').fadeIn(200).show(**); >>> $(".adddtl").fadeOut(3000); >>> } >>> >>> }); >>> >>> } >>> return false; >>> }); >>> >>> *Controller* >>> >>> class *BpagesController* < ApplicationController >>> >>> def add >>> *@number* = params[:bnumber] >>> *render 'bpages/page'* >>> end >>> end >>> >>> >>> After the function *add* i need to display the value of variable *@number >>> *in the* page.html.erb, *for that here i use the* render 'bpages/page'*. >>> But i didn't that variable. >>> or any other way to do this..?plz give one solution >>> >>> Thanks >>> vishnu >>> * >>> * >>> * >>> * >>> >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Ruby on Rails: Talk" group. >>> To view this discussion on the web visit https://groups.google.com/d/** >>> msg/rubyonrails-talk/-/**mH1pNmw_6e4J<https://groups.google.com/d/msg/rubyonrails-talk/-/mH1pNmw_6e4J> >>> . >>> To post to this group, send email to >>> rubyonrails-talk@googlegroups.**com<rubyonrails-talk@googlegroups.com> >>> . >>> To unsubscribe from this group, send email to >>> rubyonrails-talk+unsubscribe@**googlegroups.com<rubyonrails-talk%2bunsubscr...@googlegroups.com> >>> . >>> 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> >>> . >>> >> >> >> >> -- >> - Aziz M. Bookwala >> >> Website <http://azizmb.in/> | Twitter <https://twitter.com/azizbookwala> >> | Github <http://github.com/azizmb> >> >> > On Thursday, 24 May 2012 08:32:42 UTC-4, azizmb.in wrote: >> >> Hi Vishnu >> >> Users on this group are not here to *give* you solutions, rather to >> point you in the correct direction. >> >> To point you in the correct direction, you need to respond to the js >> format<http://whoneedsactions.com/blog/2010/10/24/jquery-ajax-with-rails-respond-to-format-dot-js/>, >> and then update the number on your page in the success function of the ajax >> call. >> >> > > I have edited like this > > From the controller i have return one json value. so how to get this json > value in ajax, bcz i was calling this controller via ajax > > *Controller* > > class *BpagesController* < ApplicationController > > def add > *@number* = params[:bnumber] > respond_to do |format| > format.html > response = { :points => @number} > format.json { render :json => response } > end > *render 'bpages/page'* > end > end > > *Header.js* > > $(".*addsubmit*").click(**function() { > var bnum = $("#bnum").val(); > var dataString = 'bnumber='+ bnum; > > if(bnum=='' ) > { > $('.adderror').fadeIn(300).**show(); > $('.adderror').fadeOut(3000); > } > else > { > > $.ajax({ > type: "POST", > url: "http://localhost:3000/bpages/**add<http://localhost:3000/bpages/add> > ", > data: dataString, > success: function(){ > > $('.adddtl').fadeIn(200).show(**); > $(".adddtl").fadeOut(3000); > } > > }); > > } > return false; > }); > > > Thank you > > >> >> On Thu, May 24, 2012 at 4:43 PM, amruby <vgrkrish...@gmail.com> wrote: >> >>> Hi >>> * *I think this is my 4 or 5th post about the ajax issues with my >>> rails code. But i couldn't rectify my issues sofar. >>> problem is, >>> >>> In my pages.html.erb have one text field and button. when i click on >>> that button, the text field value will get into the controller through >>> ajax,so after the function i need to get that value(textfield value) in >>> same page. >>> >>> *page.html.erb* >>> >>> <%= form_tag({:controller => 'bpages',:action => 'add' }, {:method => >>> :post}) do %> >>> >>> <%= text_field_tag('Bnum' ,nil, :id => "bnum") %> >>> <%= submit_tag "Add", :id => "addbtn", :class => "*addsubmit* btn >>> btn-large btn-success" %> >>> <%end%> >>> <div class="adddtl" >>> <strong><%= *@number*%></strong> added >>> </div> >>> >>> Here is my ajax part >>> >>> *header.js* >>> * >>> * >>> $(".*addsubmit*").click(**function() { >>> var bnum = $("#bnum").val(); >>> var dataString = 'bnumber='+ bnum; >>> >>> if(bnum=='' ) >>> { >>> $('.adderror').fadeIn(300).**show(); >>> $('.adderror').fadeOut(3000); >>> } >>> else >>> { >>> >>> $.ajax({ >>> type: "POST", >>> url: "http://localhost:3000/bpages/**add<http://localhost:3000/bpages/add> >>> ", >>> data: dataString, >>> success: function(){ >>> >>> $('.adddtl').fadeIn(200).show(**); >>> $(".adddtl").fadeOut(3000); >>> } >>> >>> }); >>> >>> } >>> return false; >>> }); >>> >>> *Controller* >>> >>> class *BpagesController* < ApplicationController >>> >>> def add >>> *@number* = params[:bnumber] >>> *render 'bpages/page'* >>> end >>> end >>> >>> >>> After the function *add* i need to display the value of variable *@number >>> *in the* page.html.erb, *for that here i use the* render 'bpages/page'*. >>> But i didn't that variable. >>> or any other way to do this..?plz give one solution >>> >>> Thanks >>> vishnu >>> * >>> * >>> * >>> * >>> >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Ruby on Rails: Talk" group. >>> To view this discussion on the web visit https://groups.google.com/d/** >>> msg/rubyonrails-talk/-/**mH1pNmw_6e4J<https://groups.google.com/d/msg/rubyonrails-talk/-/mH1pNmw_6e4J> >>> . >>> To post to this group, send email to >>> rubyonrails-talk@googlegroups.**com<rubyonrails-talk@googlegroups.com> >>> . >>> To unsubscribe from this group, send email to >>> rubyonrails-talk+unsubscribe@**googlegroups.com<rubyonrails-talk%2bunsubscr...@googlegroups.com> >>> . >>> 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> >>> . >>> >> >> >> >> -- >> - Aziz M. Bookwala >> >> Website <http://azizmb.in/> | Twitter <https://twitter.com/azizbookwala> >> | Github <http://github.com/azizmb> >> >> -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/rubyonrails-talk/-/zVNPui_Pk3sJ. > > To post to this group, send email to rubyonrails-talk@googlegroups.com. > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > -- - Aziz M. Bookwala Website <http://azizmb.in/> | Twitter <https://twitter.com/azizbookwala> | Github <http://github.com/azizmb> -- 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. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.