mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 18:55:26 +00:00
feature(load) ajax: stringify if data is object
This commit is contained in:
parent
fc446a3df1
commit
7bc583c4ff
2 changed files with 10 additions and 12 deletions
|
|
@ -157,7 +157,9 @@ var Util, DOM;
|
|||
* @param pParams
|
||||
*/
|
||||
load.ajax = function(params) {
|
||||
var p = params, countProgress,
|
||||
var data,
|
||||
p = params, countProgress,
|
||||
isObject = Util.isObject(p.data),
|
||||
type = p.type || p.method || 'GET',
|
||||
xhr = new XMLHttpRequest();
|
||||
|
||||
|
|
@ -166,6 +168,11 @@ var Util, DOM;
|
|||
if (p.responseType)
|
||||
xhr.responseType = p.responseType;
|
||||
|
||||
if (isObject)
|
||||
data = Util.stringifyJSON(p.data);
|
||||
else
|
||||
data = p.data;
|
||||
|
||||
Events.add('progress', xhr.upload, function(event) {
|
||||
var percent, count;
|
||||
|
||||
|
|
|
|||
|
|
@ -143,26 +143,17 @@ var Util, DOM, CloudFunc;
|
|||
|
||||
function sendRequest(params) {
|
||||
var p = params,
|
||||
apiURL = CloudFunc.apiURL,
|
||||
data,
|
||||
isString = Util.isString(p.data),
|
||||
isArrayBuffer = Util.isArrayBuffer(p.data),
|
||||
isFile = Util.isFile(p.data);
|
||||
apiURL = CloudFunc.apiURL;
|
||||
|
||||
if (Util.isString(p.url))
|
||||
p.url = decodeURI(p.url);
|
||||
|
||||
if (p.data && !isString && !isArrayBuffer && !isFile)
|
||||
data = Util.stringifyJSON(p.data);
|
||||
else
|
||||
data = p.data;
|
||||
|
||||
p.url = apiURL + p.url;
|
||||
|
||||
DOM.load.ajax({
|
||||
method : p.method,
|
||||
url : p.url,
|
||||
data : data,
|
||||
data : p.data,
|
||||
dataType : p.dataType,
|
||||
error : Images.showError,
|
||||
success : function(data) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue