I have found that you have to use post AND serialize your data in order to get it to work.
function dofill(url) { var options = { method: 'post', parameters: $('myform').serialize(), // just serialize for the one item onSuccess: fill_in, onFailure: ajax_err, on0: ajax_err }; new Ajax.Request( http://0.0.0.0:3000/, options ); On Sat, Jul 30, 2011 at 11:53 AM, emygdio <rodrigo.emyg...@gmail.com> wrote: > Hi, > > I have a script that takes the value of selected option in a form, > and makes a request ajax to a rails application. The ideia will be > make a ajax request and return a option string to populate a select. > At this moment I just made some tests, when the prototype makes a > ajax request, this request wasn't made with post method. And the rails > didn't understood the method used by request, as you can see bellow: > > The script: > <pre> > <script type="text/ > javascript"> > // we will add our javascript code here > var SelectSubCat = Class.create(); > SelectSubCat.prototype = { > initialize: function(select){ > this.category = $(select); > this.category.onchange = > this.request_ajax.bindAsEventListener(this); > }, > > request_ajax: function(e){ > new Ajax.Request("http://0.0.0.0:3000/ > search_sub_cat_and_return_option_to_select.json", { > > method: 'post', > > parameters: {id: this.category.value}, > > onSuccess: function(transport){ > > var json = transport.responseText.evalJSON(); > > } > }); > alert(json); > } > }; > > > > > </script> > <form> > <select name="cat" id="cat" size="0"> > <option value="54" >Academia</option> > <option value="54" >Restaurante</option> > <option value="54" >Bares</option> > </select> > <select name="sub" id="sub"> > <option value="">-- Selecione Sub > Categorias --</otion> > </select> > </form> > </pre> > > When the request was made with the ajax, the following message I see > in the console: > > Started OPTIONS "/search_sub_cat_and_return_option_to_select.json" for > 127.0.0.1 at Sat Jul 30 12:05:54 -0300 2011 > DEPRECATION WARNING: You are using the old router DSL which will be > removed in Rails 3.1. Please check how to update your routes file at: > http://www.engineyard.com/blog/2010/the-lowdown-on-routes-in-rails-3/. > (called from /home/emygdio/Documentos/Projetos/GuiaDF/ > ws_guia_comercial_df/config/routes.rb:1) > > ActionController::RoutingError (No route matches "/ > search_sub_cat_and_return_option_to_select.json"): > > > I made some test with another form post, to test the request to rails > as you can see bellow: > <form action="http://0.0.0.0:3000/ > search_sub_cat_and_return_option_to_select.json" method='post'> > <select name="id" id="cat" size="0"> > <option value="54" >Academia</option> > <option value="54" >Restaurante</option> > <option value="54" >Bares</option> > </select> > <input type=submit> > </form> > > > And the result in console was: > > Started POST "/search_sub_cat_and_return_option_to_select.json" for > 127.0.0.1 at Sat Jul 30 12:18:31 -0300 2011 > Processing by > CatK2ItemController#search_sub_cat_and_return_option_to_select as JSON > Parameters: {"id"=>"54"} > CatK2Item Load (0.1ms) SELECT `gdf_k2_categories`.* FROM > `gdf_k2_categories` WHERE `gdf_k2_categories`.`parent` = 54 > "[{option:'<option value='669'>Auditores </option><option > value='670'>Contabilidade - Escritórios </option>'}]" > Completed 200 OK in 21ms (Views: 4.1ms | ActiveRecord: 0.1ms) > > > As can you see the rails understands properly the request, but the > ajax request didn't made the request with the correct method. > How Can I fix this? > > Thanks > > -- > You received this message because you are subscribed to the Google Groups > "Prototype & script.aculo.us" group. > To post to this group, send email to > prototype-scriptaculous@googlegroups.com. > To unsubscribe from this group, send email to > prototype-scriptaculous+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/prototype-scriptaculous?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group. To post to this group, send email to prototype-scriptaculous@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.