Ext3.X 同步请求

许多需要返回结果的函数,使用ajax异步请求将得不到值,这时需要使用同步请求,代码如下
Synchronize = function(url) {

	function createXhrObject() {
		var http;
		var activeX = ["MSXML2XMLHttp.5.0","MSXML2XMLHttp.4.0","MSXML2.XMLHttp.3.0",
		               "MSXML2.XMLHttp","Microsoft.XMLHttp"];

		try {
			http = new XMLHttpRequest();
		} catch (e) {
			for (var i = 0; i < activeX.length; ++i) {
				try {
					http = new ActiveXObject(activeX[i]);
					break;
				} catch (e) {
					UICtrl.WriteToPhoneMessageBox('生成'+activeX[i]+'失败!');
				}
			}
		} finally {
			return http;
		}
	};

	var conn = createXhrObject();
	if (conn){
		conn.open("POST", url, false);
		conn.send(null);
		if (conn.responseText != '') {
			return Ext.decode(conn.responseText);
		} else {
			UICtrl.WriteToPhoneMessageBox('服务器出现错误请稍后再试!');
		}
	}else
	{
		UICtrl.WriteToPhoneMessageBox('创建HTTP请求失败!');
	}
};

你可能感兴趣的:(Ajax,ext,Microsoft)