mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-03-12 00:45:14 +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");
|
||||
};
|
||||
|
||||
this.jqAjax = function(options) {
|
||||
return (this.jqEnabled() ? window.jQuery.ajax(options) : null);
|
||||
this.jqAjax = function(url, callback, onError) {
|
||||
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() {
|
||||
|
@ -535,57 +544,42 @@ var HTTPObject = function(engine) {
|
|||
return this;
|
||||
};
|
||||
|
||||
this.post = function(url, callback) {
|
||||
this.post = function(url, callback, onError) {
|
||||
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) {
|
||||
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 {
|
||||
if (this.jqEnabled()) {
|
||||
return this.jqAjax({
|
||||
type: "GET",
|
||||
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);
|
||||
}
|
||||
});
|
||||
this.setMethod("GET");
|
||||
this.jqAjax(url, callback, onError);
|
||||
} else {
|
||||
return this.open("GET", url).send(callback);
|
||||
}
|
||||
} 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 {
|
||||
if (this.jqEnabled()) {
|
||||
return this.jqAjax({
|
||||
type: "PATCH",
|
||||
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);
|
||||
}
|
||||
});
|
||||
this.setMethod("PATCH");
|
||||
this.jqAjax(url, callback, onError);
|
||||
} else {
|
||||
throw Error("PATCH does not supported on GUI mode");
|
||||
return this.open("PATCH", url).send(callback);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("HTTPObject.patch() ->", e.message);
|
||||
if (typeof onError === "function") onError(this, null, e);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user