Use Atlas to implement a Ajax-based non-refreshing chatroom

Source: Internet
Author: User
Atlas is an Ajax Toolkit provided by Microsoft. It encapsulates the java scripts required for Ajax implementation. It is very simple to use and can directly call the Web service method, then we call back the client script through asynchronous call. I used Atlas to write a simple Ajax-based non-refreshing chatroom:

Atlas chatroom
Http://www.worong.com/atlaschat/

To reference the web service, add the following client script to the page:

< Script Language = " Javascript " SRC = " Chatservice. asmx/JS " />

The call to display and add a message is as follows. Three parameters are required for each method call: the parameters of the web service method, the callback function after successful calls, And the callback function that calls timeout.
Function Getmsg () {
Atlschat. chatservice. getconversation (
"" , // Params
Oncomplete, // Complete Event
Ontimeout // Timeout event
);

Return   False ;
}

Function Add () {
Document. getelementbyid ('info'). innerhtml = ' < SPAN Style = " Background-color: Yellow " > & Nbsp; posting & Nbsp; </ Span > ';
Atlschat. chatservice. Add (
Document. getelementbyid ('inputname'). value. Replace ('\ t ',' & Nbsp; & Nbsp; & Nbsp ;') + '\ T' + Document. getelementbyid ('inputmsg '). value. Replace (' \ t ',' & Nbsp; & Nbsp; & Nbsp ;'),
Getmsg,
Ontimeout
);

Return   False ;
}

Function Oncomplete (result)
{
Document. getelementbyid ('msg '). innerhtml=Result;

Document. getelementbyid ('info'). innerhtml= "";
}

Function Ontimeout (result)
{
Document. getelementbyid ('info'). innerhtml= "Time out";
}

Finally, you need to reference several JS files provided by Atlas on the page:

< Atlas: script ID = " Script1 " Runat = " Server " Path = " ~ /Scriptlibrary/atlascompat. js " Browser = " Mozilla "   />
< Atlas: script ID = " Script2 " Runat = " Server " Path = " ~ /Scriptlibrary/atlascompat. js " Browser = " Firefox "   />
< Atlas: script ID = " Script3 " Runat = " Server " Path = " ~ /Scriptlibrary/atlascompat. js " Browser = " Applemac-Safari "   />
< Atlas: script ID = " Script4 " Runat = " Server " Path = " ~ /Scriptlibrary/atlascore. js "   />
< Atlas: script ID = " Script5 " Runat = " Server " Path = " ~ /Scriptlibrary/atlascompat2.js " Browser = " Applemac-Safari "   />

  < Script Type = " Text/XML-script " >
< Page xmlns: script = " Http://schemas.microsoft.com/xml-script/2005 " >
< References >
<! -- Repath the following SRC attributes, using regular client relative paths as necessary -->
< Add SRC = " Scriptlibrary/atlasui. js "   />
< Add SRC = " Scriptlibrary/atlascontrols. js "   />
</ References >
< Components >
</ Components >
</ Page >
</ Script >

Is the official website of Atlas http://beta.asp.net/default.aspx? Tabindex = 7 & Tabid = 47. Although it provides support for non-ie browsers, updating the DIV in Firefox will refresh the page and won't work on Mac safari.

Related Article

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.