欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Ajax+ASP和Flash+ASP数据读取取方法有些相似的实现方法

程序员文章站 2023-11-20 20:11:34
ajax+asp和flash+asp数据存取方法两种数据存取方法差不多。===============================下面是一个chatroom的ajax部...
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