ajax的get传输和post传输

首先获取xmlHttpapp

//建立xmlHttp
	function createXmlHttp() {
		var xmlHttp = null;
		if (window.ActiveXObject) {
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		} else if (window.XMLHttpRequest) {
			xmlHttp = new XMLHttpRequest();
		}
		return xmlHttp;
	}

若是使用get方法的话,能够写做:post

function a(number){
		var xmlHttp = createXmlHttp();
		xmlHttp.onreadystatechange = function() {
			if (xmlHttp.readyState == 4) {
				if (xmlHttp.status == 200) {
					
				}
			}
		};
		var url = "a.action?a.number="+number;
		xmlHttp.open("GET", url, true);
		xmlHttp.send(null);
	}

若是使用post方法的话,能够写做:url

function b(number){
		var xmlHttp = createXmlHttp();
		xmlHttp.onreadystatechange = function() {
			if (xmlHttp.readyState == 4) {
				if (xmlHttp.status == 200) {
				
				}
			}
		};
		var url = "b.action";
		var string = "b.number=" + number;
		xmlHttp.open("POST", url, true);
		//失去这一条POST就没法识别
		xmlHttp.setRequestHeader("Content-Type",
				"application/x-www-form-urlencoded");
		xmlHttp.send(string);
	}
相关文章
相关标签/搜索