AJAX encapsulation class user guide and ajax encapsulation User Guide

Source: Internet
Author: User

AJAX encapsulation class user guide and ajax encapsulation User Guide

AJAX is hard to say, but if you encapsulate it, you will find it easy to use. Of course, it is also a simple application, such as the application of message boards. First of all, first to give you a gift that is encapsulated AJAX class, http://xiazai.jb51.net/201412/yuanma/ajax3.0 (jb51.net#.rar here download this class, and then teach you how to use it!
Instance!

Copy codeThe Code is as follows:
<Html>
<Head>
<Title> Ajax instance </title>
<Script src = "ajax3.0.js"> </script>
</Head>
<Body>
<Script>
Document. write (new Date () + "<br> ");
Document. write (new Date () + "<br> ");
Document. write (new Date () + "<br> ");
</Script>
<Div id = "show" style = "background: yellow; border: 1px solid blue">
Loading content .....
</Div>
<Script>
Function read (){
Ajax (). get ("read. php? Num = "+ Math. random (), function (data ){
Document. getElementById ("show"). innerHTML = data;
})
}
Read ();
SetInerval ("read ()", 3000 );
Function send (){
Var username = document. frm. username;
Var desn = document. frm. desn;
Var datao = {username: username. value, desn: desn. value };
Ajax (). post ("save. php", datao, function (data ){

Read ();
Username. value = "";
Desn. value = "";
});
}
</Script>
<Form name = "frm">
Username: <input type = "text" name = "username" value = "> <br>
Content: <textarea cols = "40" rows = "5" name = "desn"> </textarea>
<Input type = "button" onclick = "send ()" value = "">
</Form>
<Script>
Document. write (new Date () + "<br> ");
Document. write (new Date () + "<br> ");
Document. write (new Date () + "<br> ");
</Script>
</Body>
</Html>

First, add our ajax3.0.js file, and then write this file Ajax (). post ("save. php", datao, function (data ))
Ajax () two parameters: the first to return xml json or html, the second to true, asynchronous transmission, false, synchronous transmission, post, you can understand it.
Below is the php File

Copy codeThe Code is as follows:
// Read. php
@ Readfile ("demo.txt ");
// Save. php
// Header ("Content-Type: text/html; charset = gb2312 ")
$ Username = $ _ POST ["username"];
$ Desn = $ _ POST ["desn"];

$ Fh = fopen ("demo.txt", "");

$ Text = $ username. "--". date ("Y-m-d H: I: s"). "said:". $ desn. "<br> ";

Fwrite ($ fh, $ text );

Fclose ($ fh );
// Demo. text
Fdsafdsa -- 12:24:04 said: fdsafdsa <br> fdsafdsa -- 12:24:07 said: fdsafdsafsa <br> 111--2012-11-01 12:25:07 said: 2222 <br> eeee -- 12:25:10 said: eeee <br> fdsfds -- 12:25:12: Comment <br> fdsfds -- 12:25:19: fdsfdsfs <br> fdsfdsf -- 12:25:22: Comment <br> fdsafdsa -- 12:26:00 said: fdsafdsa <br>

Well, today is something that may not be detailed enough. If you have any questions, please leave a message,

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.