ajax发送同步请求


首先需要导入jquery,然后才能使用下面的function

function ajax_sync(url, method, param) {
	var resultJson;
	if (method == '' || method == undefined || method == null) {
		method = 'post';
	}

	$.ajax({
		url: url,//  请求地址
		type: method,//  提交方式
		data: param,//   请求的数据
		async: false,
		dataType:"json",//   服务器返回值的类型   xml/text/html/json
		success:function(result){//成功   result:服务器返回的请求数据
			resultJson = result;
		},
		error: function (XMLHttpRequest, textStatus, errorThrown) { //失败  error:失败
			console.log(XMLHttpRequest.status); // 状态码
			console.log(XMLHttpRequest.readyState); // 状态
			console.log(textStatus); // 错误信息 
		}
	});
	return resultJson;
}

var a = ajax_sync("http://127.0.0.1:8080/stuapp_web/anonymity/dict/list_all_by_parent_code", "get", {'code':'OTHER_DECLARE'});


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM