Simple frameless Ajax application

Source: Internet
Author: User
If you must add an Ajax framework to apply Ajax, let the service provider install the framework you want to use on the server, for example, when buying a virtual host space, it is a very troublesome event or an event that cannot be completed. so let's take a look at Ajax applications by ourselves.
In fact, it is easy to use the XMLHTTP object of JS.
In IE, it is declared as follows: var oBao = new ActiveXObject ("Microsoft. XMLHTTP ");

The following is an example of an application. It is very simple to read an array of content. I believe you can understand the most basic Ajax information after reading it. This example can be extended to read articles by bar.

First, we create a page that responds to the JS call content. this page is used to obtain the index of the array content to be read. get its content from the array and return it to JS. How can this problem be returned? Response. Write (). The returned content of a page is its output content.

The content of art. aspx is as follows: <% @ Page Language = "C #" %>


<Script runat = "server">
Private String [] Strs = new String [3];

Protected void Page_Load (object sender, EventArgs e)
{
Strs [0] = "This is the first one! ";
Strs [1] = "this is the second! ";
Strs [2] = "this is the third! ";
Int32 num = Int32.Parse (Request ["id"]);
Response. Clear ();
If (num <Strs. Length)
{
Response. Write (DateTime. Now. ToString ("hh: mm: ss") + "-" + Strs [num]);
}
Else
{
Response. Write ("no more! ");
}

}
</Script>

Next, we need to create a call page.
The Content on the page is very simple: a DIV is used to display the Content. ID = Content, and then there is a button to call the JS Loadart () function when you click it to get the Content and display it.
The content of Default. aspx is as follows: <Head runat = "server">
<Title> Ajax article reading demonstration </title>
<Script type = "text/javascript">
Var I = 0;
Function loadart ()
{

Var content = document. getElementById ("content ");
Var oBao = new ActiveXObject ("Microsoft. XMLHTTP ");
OBao. open ("Get", "art. aspx? Id = "+ I, false );
OBao. send ();
Content. innerHTML = oBao. responseText;
If (I <3)
{I ++ ;}
Else
{I = 0 ;}

}
</Script>
</Head>
<Body>

<Div id = "content">
</Div>
<Input type = "button" onclick = "loadart ()" value = "Next"/>

</Body>
</Html>

Now, let's test it. Put the two pages together. Of course, if you don't want to put them together, you have to write the complete path for the address in oBap. open.
Everything is so simple. Extend art. aspx and you can let it read the database so that your information content can be browsed by entries.

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.