mui中ajax请求(自己用)

POST请求

mui.ajax('http://server-name/login.php',{
	data:{
		username:'username',
		password:'password'
	},
	dataType:'json',//服务器返回json格式数据
	type:'post',//HTTP请求类型
	timeout:10000,//超时时间设置为10秒;
	headers:{'Content-Type':'application/json'},	              
	success:function(data){
		//服务器返回响应,根据响应结果,分析是否登录成功;
		...
	},
	error:function(xhr,type,errorThrown){
		//异常处理;
		console.log(type);
	}
});

mui.post(url[,data][,success][,dataType])

mui.post('http://server-name/login.php',{
		username:'username',
		password:'password'
	},function(data){
		//服务器返回响应,根据响应结果,分析是否登录成功;
		...
	},'json'
);

GET请求

mui.ajax('http://server-name/list.php',{
	data:{
		category:'news'
	},
	dataType:'json',//服务器返回json格式数据
	type:'get',//HTTP请求类型
	success:function(data){
		//获得服务器响应
		...
	}
});

mui.get(url[,data][,success][,dataType])

mui.get('http://server-name/list.php',{category:'news'},function(data){
		//获得服务器响应
		...
	},'json'
);

mui.getJSON()
此方法限定返回json格式数据
mui.getJSON(url[,data][,success])

mui.getJSON('http://server-name/list.php',{category:'news'},function(data){
		//获得服务器响应
		...
	}
);

猜你喜欢

转载自blog.csdn.net/zx19930309/article/details/90200632