get请求

function zhankai(id){/*函数:展开某个分类*/
	var httpRequest = new XMLHttpRequest () ;
	httpRequest.open('GET',"/d/js/class/class"+id+"_newnews.js", true);
	httpRequest.send();
	httpRequest.onreadystatechange = function () {
		if (httpRequest.readyState == 4 && httpRequest.status == 200) {
		var json = httpRequest.responseText;//获取到json字符串,还需解析
			json=json.replace('document.write\("<ul>',"");
			json=json.replace('</ul>"\);',"");
			json=json.replace(/\\/g,"");/*替换反斜杠*/
			document.getElementById("zhanwei_"+id).innerHTML=json;
			document.getElementById("zhanwei_"+id).previousElementSibling.previousElementSibling.className="jianhao";
		}
	}
}

post请求

function shengcheng(){
		var httpRequest = new XMLHttpRequest() ;
		httpRequest.open('POST',"admin/function.pinyin.php", true);
			data = new FormData();
			data.append("user", "张三");
		httpRequest.send(data);
		httpRequest.onreadystatechange = function () {
			if (httpRequest.readyState == 4 && httpRequest.status == 200) {
			var str = httpRequest.responseText;
				document.getElementById("keywordspinyin").value=str;
			}
		}
	}