Hello,

I just upgraded my Prado PHP Framework version which includes
Prototype 1.5.1rc2 (not rc3)
and I noticed some of my Ajax calls were not being returned properly
on further
inspection I noticed that the toQueryParam method was not outputting
the proper data.

Here is the string I had.
"http://mysite.com/ajax.php?
page=myPage&param=id=image_41,sid=47,sat=us,plo=-1|
id=image_42,sid=44,sat=us,plo=-1"

toQueryParams would output:
{
  page: "myPage",
  param:"id"
};

Should have output:
{
  page: "myPage",
  param: "id=image_41,sid=47,sat=us,plo=-1|
id=image_42,sid=44,sat=us,plo=-1"
};


To resolve this I modified the method

Ajax.Base.prototype.setOptions =  function(options) {
    this.options = {
        method:          'post',
        asynchronous: true,
        contentType:   'application/x-www-form-urlencoded',
        encoding:        'UTF-8',
        parameters:     ''
    };

    Object.extend(this.options, options || {});
    this.options.method = this.options.method.toLowerCase();

    //my fix
    var params = this.options.parameters;
    if(typeof params == 'string'){

        var arr  = params.substring( params.indexOf('?')
+1 ).split('&');
        var hash = {};

        arr.each(function(item){

            var pair = ( item.match(/^(\w+)(?:(?:\s|%20)*=)(.+)/) ||
[,,] );

            if(pair[1] && pair[2]){
                hash[pair[1]] = pair[2];
            }
        });

        this.options.parameters = $H(hash);
    }
}

Methods from my Utility class I use.


/* * * * * * * * * * * * * * * * * * *
*
*    Core.resolveHash()
*
* * * * * * * * * * * * * * * * * * */

resolveHash : function(hash, splitBy){

    var isString = this.isString(hash);
    var isObject = this.isObject(hash);
    var isHash   = (hash && hash.constructor == Hash);
    var splitBy  = splitBy || '&';

    if(isString){

        var arr  = hash.substring( hash.indexOf('?')
+1 ).split( splitBy);
        var hash = {};

        arr.each(function(item){

            var pair = ( item.match(/^(\w+)(?:(?:\s|%20)*=)(.+)/) ||
[,,] );

            if(pair[1] && pair[2]){
                hash[pair[1]] = pair[2];
            }
        });

        return $H(hash);
    }

    if(isObject || isHash){
        return (hash.toQueryString)? hash : $H(hash);
    }

    return false;
},


/* * * * * * * * * * * * * * * * * * *
*
*    Core.copyHash()
*
* * * * * * * * * * * * * * * * * * */

copyHash : function(hash){

    return this.resolveHash( hash.toQueryString() );
},


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype: Core" group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to