Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Catalyst: Users

jQuery gotcha

 

 

Catalyst users RSS feed   Index | Next | Previous | View Threaded


keenlinks at ymail

Jan 31, 2010, 8:13 PM

Post #1 of 2 (681 views)
Permalink
jQuery gotcha

Found a change in the latest jQuery (1.4.1) from the previous release I used (1.3.2) that affected a Catalyst app of mine. Regarding form field submissions, jQuery now submits multiple checkbox (or select) values with the variable name followed by the array "[]" brackets (probably to appease PHP). I had a problem with a previous working app and used firebug to look at my JSON post and found the brackets.

What used to be:

tags 25
tags 18
tags 10

is now:

tags[] 25
tags[] 18
tags[] 10

Changing:

my $tags = $c->request->params->{tags};

to:

my $tags = $c->request->params->{'tags[]'};

corrected it (the quotes are needed). Hope this is helpful.

This was my first post, been reading forums for awhile and want to thank all of you for the skill and knowledge you offer. I thank you for the forum posts, blogs, calendars and books. I am not a trained programmer, but with your help I have been able to build a few production Catalyst apps.

Thanks,
Scott K.


garrison at zeta

Jan 31, 2010, 10:03 PM

Post #2 of 2 (656 views)
Permalink
Re: jQuery gotcha [In reply to]

Good afternoon,

On 31/01/10 at 8:13 PM -0800, S.A. Kiehn <keenlinks [at] ymail> wrote:

>Found a change in the latest jQuery (1.4.1) from the previous
>release I used (1.3.2) that affected a Catalyst app of mine. 
>Regarding form field submissions, jQuery now submits multiple
>checkbox (or select) values with the variable name followed by
>the array "[]" brackets (probably to appease PHP).  I had a
>problem with a previous working app and used firebug to look at
>my JSON post and found the brackets.

In some of the info about the new version, they talk about the
new feature:

<http://jquery14.com/day-01>

Nested param serialization (jQuery.param() Documentation,
Commit 1, Commit 2)

jQuery 1.4 adds support for nested param serialization in
jQuery.param, using the approach popularized by PHP, and
supported by Ruby on Rails. For instance, {foo: ["bar", "baz"]}
will be serialized as “foo[]=bar&foo[]=baz”.

In jQuery 1.3, {foo: ["bar", "baz"]} was serialized as
“foo=bar&foo=baz”. However, there was no way to encode a
single-element Array using this approach. If you need the old
behavior, you can turn it back on by setting the traditional
Ajax setting (globally via jQuery.ajaxSettings.traditional or on
a case-by-case basis via the traditional flag).

So rather than changing the name of params you use, change the
behaviour of jQuery instead:

<http://api.jquery.com/jQuery.param/>

jQuery.ajaxSettings.traditional = true;

Note, I haven't tried the above yet. But I think that's because
MyApp uses Params::Nested which effectively normalizes the param
names for $c->req, so the extra brackets haven't been an issue.

In either case, I had forgotten about that factoid in the
release docco; thanks for the notice.


Charlie

--
Ꮚ Charlie Garrison ♊ <garrison [at] zeta>
〠 PO Box 141, Windsor, NSW 2756, Australia

O< ascii ribbon campaign - stop html mail - www.asciiribbon.org
http://www.ietf.org/rfc/rfc1855.txt

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/

Catalyst users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.