function ajaxSendPost(url, values, processRequest) {
ajaxHttpRequest.open("POST",url,true);
ajaxHttpRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
ajaxHttpRequest.send(values);
ajaxHttpRequest.onreadystatechange = processRequest;
}
/*
function ajaxSendGet(url) {
ajaxHttpRequest.open("GET",url,true);
ajaxHttpRequest.send(null);
ajaxHttpRequest.onreadystatechange = processRequest;
}
*/
ajaxInit();
var sound = false;
var isMove = true;
function send() {
var msg=escape((document.getElementById("msg")).value); //escape解決Ajax中文籌碼問題
if(msg=="") {
setSuggest("請輸入內容");
}
else {
var color = document.getElementById("selectColor").value;
var values = "msg=" + msg + "&color=" + color;
ajaxSendPost("process.asp", values, processSendRequest);
document.getElementById("msg").value = "";
document.getElementById("msg").focus();
}
}
function processSendRequest() {
if(ajaxHttpRequest.readyState==4) {
if(ajaxHttpRequest.status==200) {
if(ajaxHttpRequest.responseText!="") {
var chatContent = document.getElementById("chat_content");
var msgDiv = document.createElement("div");
msgDiv.innerHTML = ajaxHttpRequest.responseText;
chatContent.appendChild(msgDiv);
sound = true;
}
}
else {
setSuggest("您請求的頁面有異常");
//alert("您請求的頁面有異常");
}
}
}
function getAllMsg() {
setSuggest(" ");
ajaxSendPost("process.asp","",processSendRequest);
if(sound) {
setSuggest("<embed type=\"application/x-mplayer2\" src=\"sound/message.wav\"
autostart=\"true\" loop=\"false\" height=0 width=0 /> ");
sound=false;
}
}
function IamComing() {
ajaxSendPost("iamcoming.asp", "", processSendRequest);
(document.getElementById("msg")).focus();
}
function showOnline() {
ajaxSendPost("showOnline.asp", "", processShowOnline);
}
function processShowOnline() {
if(ajaxHttpRequest.readyState==4) {
if(ajaxHttpRequest.status==200) {
if(isFinite(ajaxHttpRequest.responseText)) {
document.getElementById("online").innerHTML =
ajaxHttpRequest.responseText;
}
}
}
}
=================================
下面是我一個Flash留言的數據讀取的部分代碼: http://www.linjimu.com.cn/Flash
ls = new LoadVars();
ls.Action = "Read";
ls.CurrentPage = _root.CurrentPage;
//ls load and send ,ld load result;
ld = new LoadVars();
ls.sendAndLoad("Advice.asp", ld, "post");
_root.gotoAndPlay("Wait");
_root.WaitBtText = "返回留言";
_root.Frame = "Send";
_root.TextMessage.text = "\n 正在讀取留言數據...\n\n 請稍後...";
ld.onLoad = function(ok) {
if (ok) {
if (this.message == "OK") {
_root.gotoAndPlay("ListView");
} else {
_root.gotoAndPlay("Wait");
_root.WaitBtText = "返回留言";
_root.Frame = "Send";
_root.TextMessage.text = " 讀取數據不成功!\n\n 可能發生以下錯誤:\n 1.
讀取數據超時,請稍後再試.\n 2.空間不支持ASP."+this.message;
}
} else {
_root.gotoAndPlay("Wait");
_root.WaitBtText = "返回留言";
_root.Frame = "Send";
_root.TextMessage.text = " 讀取數據不成功!\n\n 可能發生以下錯誤:\n 1.讀取數據
超時,請稍後再試.\n 2.空間不支持ASP.";
}
};
delete ls;
stop();
================
相比一下,他們都有相似之處:
AJax:
ajaxHttpRequest.open("POST",url,true);//發送數據的方法,類型,url地址..
ajaxHttpRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
ajaxHttpRequest.send(values);//發送數據
ajaxHttpRequest.onreadystatechange = processRequest; //processRequest是一個過程函數,對返回數據的
處理。
--------
Flash:
ls = new LoadVars();
ls.Action = "Read";//是發送數據
ls.CurrentPage = _root.CurrentPage;//是發送數據
//ls load and send ,ld load result;
ld = new LoadVars();
ls.sendAndLoad("Advice.asp", ld, "post");//發送數據的方法,類型,url地址..
ld.onLoad = function(ok) {//code...} //也是一個過程函數,對返回數據的處理。
不過,在web方面,Ajax的頁面完全基於HTML,文本網頁會更有利於搜索引擎的搜索。
Flash開發人員還是偏重圖形、動畫設計,Flash能夠更容易的調用浏覽器以外的外部資源。比如攝像頭、麥克風等。然而這是普通的HTML無法完成的。
他們的關系請去baidu一下:flash與AJAX http://www.baidu.com/s?wd=flash+ajax