Side navigation
#2377 closed bug (invalid)
Opened February 21, 2008 12:00AM UTC
Closed July 22, 2008 03:57PM UTC
Last modified July 22, 2008 04:23PM UTC
jQuery.param returns wrong data when using brackets "[ ]" in variables
Reported by: | Sincklation | Owned by: | flesler |
---|---|---|---|
Priority: | major | Milestone: | 1.3 |
Component: | ajax | Version: | 1.2.3 |
Keywords: | param | Cc: | |
Blocked by: | Blocking: |
Description
When i try to serialize a form that have variable names with brackets " var[] ", that i use with PHP because this language recognize that variables as an array, serialize use encodeURIComponent over the variable names so i obtain " var%5B%5D " the brackets encoded, if i send them that way PHP wont recognize the variable "var" as an array, so i remove it manually from jQuery code and now it's working fine.
param: function( a ) { var s = []; // If an array was passed in, assume that it is an array // of form elements if ( a.constructor == Array || a.jquery ) // Serialize the form elements jQuery.each( a, function(){ s.push( this.name + "=" + encodeURIComponent( this.value ) ); }); // Otherwise, assume that it's an object of key/value pairs else // Serialize the key/values for ( var j in a ) // If the value is an array then the key names need to be repeated if ( a[j] && a[j].constructor == Array ) jQuery.each( a[j], function(){ s.push( j + "=" + encodeURIComponent( this ) ); }); else s.push( j + "=" + encodeURIComponent( a[j] ) ); // Return the resulting serialization return s.join("&").replace(/%20/g, "+"); }
Maybe there's a better solution, or I'm doing something wrong.
Attachments (0)
Change History (4)
Changed May 11, 2008 10:32PM UTC by comment:1
component: | core → ajax |
---|
Changed May 15, 2008 01:54PM UTC by comment:2
owner: | → flesler |
---|---|
status: | new → assigned |
Changed July 22, 2008 03:57PM UTC by comment:3
milestone: | 1.2.4 → 1.3 |
---|---|
resolution: | → invalid |
status: | assigned → closed |
Ok, I just tried this with a small php file and it works well.
PHP generates an array out of the inputs.
I simply did:
<?php print_r( $_POST ); print_r( $_GET ); ?>
Tried this from firefox 2 but I assume it works the same on any browser.