答案:Ajax+ASP和Flash+ASP数据存取方法
两种数据存取方法差不多。
===============================
下面是一个ChatRoom的Ajax部分代码:
var ajaxHttpRequest = false;
function ajaxInit() {
if(window.XMLHttpRequest) { //Mozilla, Opera, ...
ajaxHttpRequest = new XMLHttpRequest();
if(ajaxHttpRequest.overrideMimeType) {
ajaxHttpRequest.overrideMimeType("text/xml");
}
}
else if(window.ActiveXObject) { //IE
try{
ajaxHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e) {
try{
ajaxHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e) {
}
}
}
if(!ajaxHttpRequest) {
window.alert("不能创建XMLHttpRequest对象实例");
return false;
}
}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