What''s the preferred method to use for encoding POST parameters for an ajax call. I was unaware that prototype did not do this under the hood, so when I have to submit a field with an "&" the server yells at me. Thanks! Daniel --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
It _does_ do it under the hood, depending on how you pass it. If you were to post a sample of your code, I suspect you''d see a host of suggestions. However, the simple answer to your question is $H().toQueryString. http://prototypejs.org/api/hash#method-toquerystringd TAG On Feb 26, 2007, at 10:34 AM, Daniel Eben Elmore wrote:> > What''s the preferred method to use for encoding POST parameters for > an ajax > call. I was unaware that prototype did not do this under the hood, > so when I > have to submit a field with an "&" the server yells at me. > > Thanks! > Daniel > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
It''s not encoding the ''website'' form field value...
var params = {
method: ''post'',
postBody: ''website='' + $(''website'').value,
evalScripts: true,
onLoading: function() { $(''website-add-indicator'').show();
},
onComplete: function() { $(''website-add-indicator'').hide();
}
}
}
new
Ajax.Request(''/index.cfm?act=admin.people.insert-website'',params);
}
-Daniel
-----Original Message-----
From: rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
[mailto:rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] On Behalf
Of Tom Gregory
Sent: Monday, February 26, 2007 11:51 AM
To: rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
Subject: [Rails-spinoffs] Re: URL Safe Ajax Encoding
It _does_ do it under the hood, depending on how you pass it. If you
were to post a sample of your code, I suspect you''d see a host of
suggestions.
However, the simple answer to your question is $H().toQueryString.
http://prototypejs.org/api/hash#method-toquerystringd
TAG
On Feb 26, 2007, at 10:34 AM, Daniel Eben Elmore wrote:
>
> What''s the preferred method to use for encoding POST parameters
for
> an ajax
> call. I was unaware that prototype did not do this under the hood,
> so when I
> have to submit a field with an "&" the server yells at me.
>
> Thanks!
> Daniel
>
>
>
> >
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
In the latest prototype (not sure which version exactly), you don''t
even have to use toQueryString manually. In fact if you look at the
source code, even if you pass it an already formatted string it will
split it back into a hash and then into a string again right before
sending the request. So, the preferred method is to give it a hash in
the first place, not a string.<br>
<br>
new Ajax.Request(''somepage'',{<br>
parameters: {<br>
key1:
"value1",<br>
key2:
"value2"<br>
}<br>
});<br>
<br>
Also, when serializing forms, there is a useHash option that I was
unaware of myself for a long time:<br>
<br>
new Ajax.Request(''somepage'',{<br>
parameters: Object.extend({<br>
key1:
"value1",<br>
key2:
"value2"<br>
}, Form.serialize(someForm, true))<br>
});<br>
<br>
Very nice. Using these methods there should rarely (if ever) be a need
for manually building a query string.<br>
<br>
Colin<br>
<br>
Tom Gregory wrote:
<blockquote
cite="mid:9F358654-3CA6-49B2-A711-19F128C53D40-PGZyUNKar/Q@public.gmane.org"
type="cite">
<pre wrap="">It _does_ do it under the hood, depending on how
you pass it. If you
were to post a sample of your code, I suspect you''d see a host of
suggestions.
However, the simple answer to your question is $H().toQueryString.
<a class="moz-txt-link-freetext"
href="http://prototypejs.org/api/hash#method-toquerystringd">http://prototypejs.org/api/hash#method-toquerystringd</a>
TAG
On Feb 26, 2007, at 10:34 AM, Daniel Eben Elmore wrote:
</pre>
<blockquote type="cite">
<pre wrap="">What''s the preferred method to use for
encoding POST parameters for
an ajax
call. I was unaware that prototype did not do this under the hood,
so when I
have to submit a field with an "&" the server yells at me.
Thanks!
Daniel
</pre>
</blockquote>
<pre wrap=""><!---->
.
</pre>
</blockquote>
<br>
--~--~---------~--~----~------------~-------~--~----~<br>
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Spinoffs" group. <br> To post to this
group, send email to
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <br> To
unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
<br> For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en <br>
-~----------~----~----~----~------~----~------~--~---<br>
</body>
</html>
<br>
I see. Because you were building the string yourself from scratch,
you could have benefitted from using the standard Javascript function
encodeURIComponent().
e.x.:
postBody: ''website='' +
encodeURIComponent($(''website'').value),
If you want Prototype to handle things for you, you could pass it
this way:
//use parameters instead of postBody
parameters: {website: $(''website'').value},
Both of these are described (in not so many words) in the API docs:
http://prototypejs.org/api/ajax/options
TAG
On Feb 26, 2007, at 11:26 AM, Daniel Eben Elmore wrote:
>
> It''s not encoding the ''website'' form field
value...
>
> var params = {
> method: ''post'',
> postBody: ''website='' +
$(''website'').value,
> evalScripts: true,
> onLoading: function() {
$(''website-add-indicator'').show();
> },
> onComplete: function() {
$(''website-add-indicator'').hide();
> }
> }
> }
> new
>
Ajax.Request(''/index.cfm?act=admin.people.insert-website'',params);
> }
>
>
> -Daniel
>
>
>
> -----Original Message-----
> From: rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
> [mailto:rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] On
Behalf Of Tom
> Gregory
> Sent: Monday, February 26, 2007 11:51 AM
> To: rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
> Subject: [Rails-spinoffs] Re: URL Safe Ajax Encoding
>
>
> It _does_ do it under the hood, depending on how you pass it. If you
> were to post a sample of your code, I suspect you''d see a host of
> suggestions.
>
> However, the simple answer to your question is $H().toQueryString.
> http://prototypejs.org/api/hash#method-toquerystringd
>
>
>
> TAG
>
> On Feb 26, 2007, at 10:34 AM, Daniel Eben Elmore wrote:
>
>>
>> What''s the preferred method to use for encoding POST
parameters for
>> an ajax
>> call. I was unaware that prototype did not do this under the hood,
>> so when I
>> have to submit a field with an "&" the server yells at
me.
>>
>> Thanks!
>> Daniel
>>
>>
>>
>>>
>
>
>
>
> >
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---