ajax封装

//ajax封装
function ajaxData(method, murl, mdata, success) {
	$.ajax({
		type: method,
		url: murl,
		dataType: "json",
		contentType: "application/json",
		data: mdata,
		timeout: 8000,
		success: function (data) {
			success ? success(data) : function () {};
		},
		error: function (data) {
			layer.msg("请求失败");
		}
	});
}

  

// 调用接口
ajaxData("POST", webUrl, usrData, function (result) {
	// console.log(result);
	var data = result.data;
	layer.msg(result.message);

	if (result.code == '000') {
		layer.msg('登录成功')
		window.localStorage.setItem("GZ_PC_TOKEN", data.token);
		window.localStorage.setItem("GZ_PC_USERID", data.userId);
		window.location.href = 'index.html';
	} else {
		if (result.code == 'USER_COM007') {
			layer.msg('账号或密码错误次数过多,该账号今日不能再登录');
		} else {
			layer.msg('账号或密码错误');
		}
	}

})

  

原文地址:https://www.cnblogs.com/rockyan/p/8522105.html