I am trying to figure out how to use Ajax with Prototype. I see from http://www.sergiopereira.com/articles/prototype.js.html#UsingAjax there is an example for a get: var empID = $F(''lstEmployees''); var y = $F(''lstYears''); var url = ''http://yourserver/app/get_sales''; var pars = ''empID='' + empID + ''&year='' + y; var myAjax = new Ajax.Request( url, { method: ''get'', parameters: pars, onComplete: showResponse }); and here is an example of a post: var url = ''edit.php''; var pars = ''id='' + obj.id + ''&content='' + new_content; var myAjax = new Ajax.Request(url, {method:''post'', postBody:pars, onSuccess:success, onFailure:failure}); What is the difference, it looks like the post and get use the same type of pars string: Post var pars = ''id='' + obj.id + ''&content='' + new_content; Get var pars = ''empID='' + empID + ''&year='' + y; Is there any difference when passing data? Thank, -T --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Remember to encode you parameters if you are planning to concatenate them like in your example. var pars = ''id='' + obj.id + ''&content='' + encodeURIComponent( new_content ); I don''t know if that''s what you''re asking, but the difference is how the parameters are sent to your server code. An HTTP GET will sim-ply put all your parameters in the querystring (in the URL) and that approach has some length limitations so don''t expect to be passing a bunch of textarea values in there. Using an HTTP POST the parameters are sent as part of the request body, without the same limitations of the GET. On the server, the way you read the values back is normally different (I don''t know what is your backend). For example in PHP you''d use $_POST vs $_GET and in ASP.NET you''d use Request.Form[ ] vs Request.QueryString[ ] Hope it helps - Sergio On May 10, 11:55 am, -T <gsecurity...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I am trying to figure out how to use Ajax with Prototype. I see fromhttp://www.sergiopereira.com/articles/prototype.js.html#UsingAjax > there is an example for a get: > > var empID = $F(''lstEmployees''); > var y = $F(''lstYears''); > var url = ''http://yourserver/app/get_sales''; > var pars = ''empID='' + empID + ''&year='' + y; > > var myAjax = new Ajax.Request( > url, > { > method: ''get'', > parameters: pars, > onComplete: showResponse > }); > > and here is an example of a post: > > var url = ''edit.php''; > var pars = ''id='' + obj.id + ''&content='' + new_content; > var myAjax = new Ajax.Request(url, {method:''post'', > postBody:pars, onSuccess:success, onFailure:failure}); > > What is the difference, it looks like the post and get use the same > type of pars string: > > Post var pars = ''id='' + obj.id + ''&content='' + new_content; > Get var pars = ''empID='' + empID + ''&year='' + y; > > Is there any difference when passing data? > Thank, > -T--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
As of Prototype 1.5.1 there is an easier step to post form $(''fomID'').request({ method: ''get'', parameters: { interests:''JavaScript'', ''hobbies[]'':[''programming'', ''music''] }, onComplete: function(){ alert(''Form data saved!'') } }) thanks YUAN On 5/10/07, -T <gsecurityone-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I am trying to figure out how to use Ajax with Prototype. I see from > http://www.sergiopereira.com/articles/prototype.js.html#UsingAjax > there is an example for a get: > > var empID = $F(''lstEmployees''); > var y = $F(''lstYears''); > var url = ''http://yourserver/app/get_sales''; > var pars = ''empID='' + empID + ''&year='' + y; > > var myAjax = new Ajax.Request( > url, > { > method: ''get'', > parameters: pars, > onComplete: showResponse > }); > > > > > and here is an example of a post: > > var url = ''edit.php''; > var pars = ''id='' + obj.id + ''&content='' + new_content; > var myAjax = new Ajax.Request(url, {method:''post'', > postBody:pars, onSuccess:success, onFailure:failure}); > > > > > What is the difference, it looks like the post and get use the same > type of pars string: > > Post var pars = ''id='' + obj.id + ''&content='' + new_content; > Get var pars = ''empID='' + empID + ''&year='' + y; > > Is there any difference when passing data? > Thank, > -T > > > > >-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "Limitless undying love which shines around me like a million suns It calls me on and on across the universe...." Accross The Universe - The Beatles - -------------------------------------------- Visit : http://www.sabukhitam.com/ ===================== --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---