Ajax+asp and flash+asp data access methods
Two methods of data access are similar.
===============================
Here is a chatroom Ajax part of the code:
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 ("Cannot create XMLHttpRequest object instance");
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 solve Ajax Chinese chip issues
if (msg== "") {
setsuggest ("Please enter Content");
&NBSP}
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 ("The page you requested has an exception");
Alert ("The page you requested has an exception");
}
}
}
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;
}
}
}
}
=================================
Below is a part of the code that reads the data from my Flash message: 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 = "return message";
_root. Frame = "Send";
_root. Textmessage.text = "\n is reading message data ...\n\n please later ...";
Ld.onload = function (ok) {
if (ok) {
if (this.message = = "OK") {
_ Root.gotoandplay ("ListView");
} else {
_root.gotoandplay ("Wait");
_root. Waitbttext = "return message";
_root. Frame = "Send";
_root. Textmessage.text = " Read data unsuccessful!\n\n The following error may occur:\n 1.
Read the data timeout, please try again later. \ n 2. Space does not support ASP. " +this.message;
}
} else {
_root.gotoandplay ("Wait");
_root. Waitbttext = "return message";
_root. Frame = "Send";
_root. Textmessage.text = "The read data is unsuccessful!\n\n The following error may occur: \ n 1. Read data
Timeout, please try again later. \ n 2. Space does not support ASP. ";
}
};
Delete ls;
Stop ();
================
They all have similarities in comparison:
Ajax:
Ajaxhttprequest.open ("POST", url,true);//Send data method, type, URL address.
Ajaxhttprequest.setrequestheader ("Content-type", "application/x-www-form-urlencoded");
Ajaxhttprequest.send (values);//Send data
Ajaxhttprequest.onreadystatechange = ProcessRequest; ProcessRequest is a process function that returns data to the
Processing.
--------
Flash:
ls = new Loadvars ();
Ls. Action = "Read";//is sending data
Ls. CurrentPage = _root. currentpage;//is sending data
LS load and send, LD load result;
LD = new Loadvars ();
Ls.sendandload ("advice.asp", LD, "POST");//method of sending data, type, URL address.
Ld.onload = function (ok) {//code ...}//is also a process function that handles the return data.
However, on the web side, Ajax pages are completely based on HTML, and text pages are more conducive to search engines.
Flash developers tend to be graphic, animated, and Flash makes it easier to invoke external resources outside of the browser. such as cameras, microphones and so on. However, this is normal HTML can not be completed.
Their relationship please go to Baidu: Flash and Ajax Http://www.baidu.com/s?wd=flash+ajax