mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-06-18 02:59:04 +00:00
Update http.js
This commit is contained in:
parent
ada2db6f77
commit
966f554d0f
28
lib/http.js
28
lib/http.js
|
@ -203,21 +203,35 @@ var HTTPObject = function() {
|
|||
}
|
||||
};
|
||||
|
||||
this.serializeURL = function(obj) {
|
||||
this.serializeURL = function(parametersObject) {
|
||||
var str = [];
|
||||
for (var p in obj)
|
||||
if (obj.hasOwnProperty(p)) {
|
||||
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
|
||||
for (var k in parametersObject) {
|
||||
if (parametersObject.hasOwnProperty(k)) {
|
||||
str.push(encodeURIComponent(k) + "=" + encodeURIComponent(parametersObject[k]));
|
||||
}
|
||||
}
|
||||
return str.join("&");
|
||||
};
|
||||
|
||||
// Type 1: http://domain?a=1&b=2&c=3
|
||||
// Type 2: http://domain/:a/:b/:c
|
||||
this.serializeParameters = function(url) {
|
||||
if (Object.keys(this.parameters).length > 0) {
|
||||
if (url.indexOf('?') > -1) {
|
||||
return url + '&' + this.serializeURL(this.parameters);
|
||||
// Type 2
|
||||
var parameters = {};
|
||||
for (var k in this.parameters) {
|
||||
if (url.indexOf(':' + k) > -1) {
|
||||
url = url.replace(':' + k, this.parameters[k]);
|
||||
} else {
|
||||
return url + '?' + this.serializeURL(this.parameters);
|
||||
parameters[k] = this.parameters[k];
|
||||
}
|
||||
}
|
||||
|
||||
// Type 1
|
||||
if (url.indexOf('?') > -1) {
|
||||
return url + '&' + this.serializeURL(parameters);
|
||||
} else {
|
||||
return url + '?' + this.serializeURL(parameters);
|
||||
}
|
||||
} else {
|
||||
return url;
|
||||
|
|
Loading…
Reference in New Issue
Block a user