mui.ajax 方法封装
作者:佚名 发表时间:2016-01-22 13:29:54
var Ajax = function (url, data, callback, cfg,errorCallBack) {
			if (!cfg) cfg = {};
			if (cfg.hasOwnProperty("async") == false) cfg.async = "true";
			if (cfg.hasOwnProperty("type") == false) cfg.type = "post";
			if (cfg.hasOwnProperty("cache") == false) cfg.cache = true;
			if (cfg.hasOwnProperty("dataType") == false) cfg.dataType = "json";
			if (cfg.hasOwnProperty("headers") == false) cfg.headers = "";
			if (!callback) {
				callback = function() {};
			}
			mui.ajax(url, {
				headers:cfg.headers,
				dataType: cfg.dataType,
				timeout: 60000,
				type: cfg.type,
				data: JSON.stringify(data),
				success: function(result, textStatus, xhr) {
					if (!!result) {
						try {
							if (!!result.Type && result.Type == "string") {
								result = result.Str;
							}
						} catch (e) {}
					}
					callback(result);
				},
				error: function(XMLHttpRequest, textStatus, errorThrown) {
					//alert(XMLHttpRequest.responseText);
					if (XMLHttpRequest.status == 401) {
						mui.toast("登录超时,请重新登录。");
					} else if (XMLHttpRequest.status == 0) {
						mui.toast("网络异常");
					} else {
						mui.toast("访问错误");
					}
					if (errorCallBack) {
						errorCallBack();
					}
				}
			});
		}