krampstudio / aja.js

Ajax without XML : Asynchronous JavaScript and JavaScript/JSON(P)
http://krampstudio.github.io/aja.js/
MIT License
306 stars 45 forks source link

the appendQueryString function Having defects #19

Closed replace5 closed 8 years ago

replace5 commented 8 years ago

sometimes, use aja().url('xxx.com').data({a: 1}).go();the request url will be 'xxx.com?&a=1', the query string start with ?&,it is not too bright, fix it with:

var appendQueryString = function appendQueryString(url, params) {
        var key;
        url = url || '';
        if (params) {
            var querystring = '';
            if (typeof params === 'string') {
                querystring = params;
            } else if (typeof params === 'object') {
                for (key in params) {
                    querystring += '&' + encodeURIComponent(key) + '=' + encodeURIComponent(params[key]);
                }
            }

            if (querystring.indexOf('&') === 0) {
                querystring = querystring.substr(1);
            }

            url += (url.indexOf('?') === -1 ? '?' : '&');
            url += querystring;
        }

        return url;
    };
krampstudio commented 8 years ago

I'll have a look

krampstudio commented 8 years ago

merged but is going to be released as part of the 0.5.0 release