mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-05-13 21:21:03 +00:00
Update http.js
This commit is contained in:
parent
31d4c26ac4
commit
d25a12bd8b
62
lib/http.js
62
lib/http.js
|
@ -94,8 +94,17 @@ var HTTPObject = function(engine) {
|
||||||
return (typeof(window) !== "undefined" && typeof(window.jQuery) !== "undefined");
|
return (typeof(window) !== "undefined" && typeof(window.jQuery) !== "undefined");
|
||||||
};
|
};
|
||||||
|
|
||||||
this.jqAjax = function(options) {
|
this.jqAjax = function(url, callback, onError) {
|
||||||
return (this.jqEnabled() ? window.jQuery.ajax(options) : null);
|
return window.jQuery.ajax({
|
||||||
|
type: this.method,
|
||||||
|
headers: this.headers,
|
||||||
|
url: this.serializeParameters(url),
|
||||||
|
data: this.requestBody,
|
||||||
|
contentType: this.contentType,
|
||||||
|
success: callback,
|
||||||
|
async: this.isAsync,
|
||||||
|
error: onError // (request, status, error)
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
this.isJSONRequest = function() {
|
this.isJSONRequest = function() {
|
||||||
|
@ -535,57 +544,42 @@ var HTTPObject = function(engine) {
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.post = function(url, callback) {
|
this.post = function(url, callback, onError) {
|
||||||
try {
|
try {
|
||||||
return this.open("POST", url).send(callback);
|
if (this.jqEnabled()) {
|
||||||
|
this.setMethod("POST");
|
||||||
|
this.jqAjax(url, callback, onError);
|
||||||
|
} else {
|
||||||
|
return this.open("POST", url).send(callback);
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("HTTPObject.post() ->", e.message);
|
if (typeof onError === "function") onError(this, null, e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.get = function(url, callback) {
|
this.get = function(url, callback, onError) {
|
||||||
try {
|
try {
|
||||||
if (this.jqEnabled()) {
|
if (this.jqEnabled()) {
|
||||||
return this.jqAjax({
|
this.setMethod("GET");
|
||||||
type: "GET",
|
this.jqAjax(url, callback, onError);
|
||||||
headers: this.headers,
|
|
||||||
url: this.serializeParameters(url),
|
|
||||||
data: this.requestBody,
|
|
||||||
contentType: this.contentType,
|
|
||||||
success: callback,
|
|
||||||
async: this.isAsync,
|
|
||||||
error: function(request, status, error) {
|
|
||||||
console.error("code: ", request.status, ", message: " + request.responseText + ", error: " + error);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
return this.open("GET", url).send(callback);
|
return this.open("GET", url).send(callback);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("HTTPObject.get() ->", e.message);
|
if (typeof onError === "function") onError(this, null, e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.patch = function(url, callback) {
|
this.patch = function(url, callback, onError) {
|
||||||
try {
|
try {
|
||||||
if (this.jqEnabled()) {
|
if (this.jqEnabled()) {
|
||||||
return this.jqAjax({
|
this.setMethod("PATCH");
|
||||||
type: "PATCH",
|
this.jqAjax(url, callback, onError);
|
||||||
headers: this.headers,
|
|
||||||
url: this.serializeParameters(url),
|
|
||||||
data: this.requestBody,
|
|
||||||
contentType: this.contentType,
|
|
||||||
success: callback,
|
|
||||||
async: this.isAsync,
|
|
||||||
error: function(request, status, error) {
|
|
||||||
console.error("code: ", request.status, ", message: " + request.responseText + ", error: " + error);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
throw Error("PATCH does not supported on GUI mode");
|
return this.open("PATCH", url).send(callback);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("HTTPObject.patch() ->", e.message);
|
if (typeof onError === "function") onError(this, null, e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user