//第一步,創建XMLHttpRequest對象
var xmlHttp = new XMLHttpRequest();
function CommentAll() {
//第二步,注冊回調函數
xmlHttp.onreadystatechange =callback1;
//{
// if (xmlHttp.readyState == 4)
// if (xmlHttp.status == 200) {
// var responseText = xmlHttp.responseText;
// }
//}
//第三步,配置請求信息,open(),get
//get請求下參數加在url后,.ashx?methodName = GetAllComment&str1=str1&str2=str2
xmlHttp.open("post", "/ashx/myzhuye/Detail.ashx?methodName=GetAllComment", true);
//post請求下需要配置請求頭信息
//xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
//第四步,發送請求,post請求下,要傳遞的參數放這
xmlHttp.send("methodName = GetAllComment&str1=str1&str2=str2");//"
}
//第五步,創建回調函數
function callback1() {
if (xmlHttp.readyState == 4)
if (xmlHttp.status == 200) {
//取得返回的數據
var data = xmlHttp.responseText;
//json字符串轉為json格式
data = eval(data);
$.each(data,
function(i, v) {
alert(v);
});
}
}
