Ajax + ASP and Flash + ASP data reading methods have similar implementation methods

Source: Internet
Author: User

Ajax + ASP and Flash + ASP data access method
The two data access methods are similar.
====================================
The following is the Ajax code of a ChatRoom:
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 object instance cannot be created ");
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 solves the Ajax Chinese chip problem
If (msg = ""){
SetSuggest ("Enter the content ");
}
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 part of the code for reading data from a 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 reading the message data... \ n please wait ...";
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 = "Data Reading failed! \ N the following error may occur: \ n 1.

Data Reading times out. Please try again later. \ n 2. The space does not support ASP. "+ this. message;
}
} Else {
_ Root. gotoAndPlay ("Wait ");
_ Root. WaitBtText = "return message ";
_ Root. Frame = "Send ";
_ Root. TextMessage. text = "Data Reading failed! \ N the following error may occur: \ n 1. Read data

Timeout. Please try again later. \ n 2. The space does not support ASP .";
}
};
Delete ls;
Stop ();
======================
They all have similarities:
AJax:
AjaxHttpRequest. open ("POST", url, true); // method of sending data, 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.

Processing.
--------
Flash:
Ls = new LoadVars ();
Ls. Action = "Read"; // send data
Ls. CurrentPage = _ root. CurrentPage; // send 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 processes the returned data.

However, in terms of web, Ajax pages are completely HTML-based, and text pages are more conducive to search engines.
Flash developers are still focusing on graphics and animation design. Flash can more easily call external resources outside the browser. For example, cameras and microphones. However, this is not possible for common HTML.

Their relationship please go to baidu: flash with AJAX http://www.baidu.com/s? Wd = flash + ajax

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.