[Html_ajax-svn] HTML_AJAX_Serialize_PHP() array indexing error

Shane Bryson sbryson at brytesun.com
Thu Jul 6 14:30:19 PDT 2006


Greetings,

I was having problems unserializing arrays with more than 9 elements via 
HTML_AJAX_Serialize_PHP() unserialize method.  It kept giving the 'missing 
ending }, or too many values for array' error.  Upon inspection of 
trunk/js/HTML_AJAX.js I found that the array size wasn't being parsed from 
the serialized string properly and so it would only work for single digit 
sizes.

Fix:

1352c1330
<             size = parseInt(cont.substring(1, divpos - 1));
---
>             size = parseInt(cont.substring(0, divpos));
1359c1337
<             for (var i = 0; i + 1 < size * 2; i += 2) {
---
>             for (var i = 0; i < size; i++) {

Info:

When size is being set cont's starting chars are the size of the array, so to 
get them we need to grab from 0 offset to the delimiter's first occurence 
position - 1. 

As for the for loop...  Not sure what the * 2, += 2 hocus pocus is for and it 
is just confusing to read, i is never even used, so I cleaned the statement 
down to stepping by 1 and cycling through the array's elements that way.

Shane Bryson



More information about the Html_ajax-svn mailing list