Ajax Encapsulation Class use guide _ajax related

Source: Internet
Author: User

Ajax is very difficult to say, but the encapsulation you will find that it is easy to use, of course, is also a simple application, such as the application of the message board, here, first of all, to send everyone a gift that is encapsulated good Ajax class, download the address http://xiazai.jb51.net/ 201412/yuanma/ajax3.0 (jb51.net). rar download this class here, and then teach you how to use it!
Example Oh!

Copy Code code as follows:

<title>ajax Example </title>
<script src= "Ajax3.0.js" ></script>
<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" >
Content loading ...
</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" >
User name: <input type= "text" name= "username" value= "" ><br>
Content: <textarea cols= "rows=" "5" name= "DESN" ></textarea>
<input type= "button" onclick= "Send ()" value= "message" >
</form>
<script>
document.write (New Date () + "<br>");
document.write (New Date () + "<br>");
document.write (New Date () + "<br>");
</script>
</body>

First join our ajax3.0.js this file, and then we'll write this thing Ajax (). Post ("save.php", Datao, Function (data))
Ajax () Two arguments first returns XML JSON or HTML second true asynchronous transmission false synchronous transmission post Well, you know what, huh?
Below is the PHP file

Copy Code code 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", "a");

$text = $username. " -". Date (" Y-m-d h:i:s ")." said: ". $desn." <br> ";

Fwrite ($FH, $text);

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

Well, there is something today, writing may not be detailed enough, what do not understand, 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.