dprevite-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Apr-23 16:27 UTC
Prototype object functions in posted ajax array
Anyone know why posting an array in an Ajax Request would send the prototype functions along with my data? function sendWarnings() { // Grab everything with the warning class name and add // it''s value to an array. var warnings = new Array(); $$(''.warning'').each(function(x, index) { warnings[index] = x.value; console.log(x.value, index); }); // Post the warnings and display the response new Ajax.Request(''ajax_send.php?tst='' + $(''tst'').value, { parameters: warnings, method: ''post'', onSuccess: function(transport) { $(''multi_send_rspnce'').innerHTML = transport.responseText; } }); } A simple print_r from PHP gives me both the data, and a bunch of prototype''s object functions. Any idea why I''d get those and not just the data? Here''s an easier to read version: http://www.pastie.org/185523 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Wed, Apr 23, 2008 at 11:27 AM, dprevite-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <dprevite-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Anyone know why posting an array in an Ajax RequestYou either want to pass a string or a Hash as the parameters value, not an Array. How would you like your post data to look when it comes in to the server? -justin --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Fixed: http://www.pastie.org/185632 Looks like $A instead of new Array() or new Object fixes it. On Wed, Apr 23, 2008 at 11:27 AM, dprevite-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <dprevite-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Anyone know why posting an array in an Ajax Request would send the > prototype functions along with my data? > > function sendWarnings() { > // Grab everything with the warning class name and add > // it''s value to an array. > var warnings = new Array(); > $$(''.warning'').each(function(x, index) { > warnings[index] = x.value; > console.log(x.value, index); > }); > > // Post the warnings and display the response > new Ajax.Request(''ajax_send.php?tst='' + $(''tst'').value, { > parameters: warnings, > method: ''post'', > onSuccess: function(transport) { > $(''multi_send_rspnce'').innerHTML = transport.responseText; > } > }); > } > > > A simple print_r from PHP gives me both the data, and a bunch of > prototype''s object functions. Any idea why I''d get those and not just > the data? > > Here''s an easier to read version: http://www.pastie.org/185523 > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Dan Previte wrote:> Fixed: > > http://www.pastie.org/185632 > > Looks like $A instead of new Array() or new Object fixes it.Note that you can use pluck() or collect() instead of each() and push(): var warnings = $$(''.warning'').pluck(''value''); or var warnings = $$(''.warning'').collect($F); - Ken Snyder --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Wed, Apr 23, 2008 at 2:17 PM, Dan Previte <dprevite-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Looks like $A instead of new Array() or new Object fixes it.Ahh, yes. I was looking at the Ajax.Base#initialize method which only parses out Strings or Hashes. If you look a little further, at the request method, the code converts the parameters to a query string via: Object.toQueryString(params). However it looks like if you do this on an Array object, you will get a lot more than you are expecting... Run this in Firebug: Object.toQueryString($A()) vs.: Object.toQueryString($H()) -justin --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---