Peng's jquery Ajax code .. Super simple ..

Source: Internet
Author: User

Now I want to write Ajax teaching materials .. It's actually super simple ..

In the past, it was only for IE .. You can write a function to get ko .. But now there are plenty of browsers .. Let's get it.

Sometimes there is no way .. Supports IE .. Supports ff .. I am very lazy ..

Now that you have an Ajax framework .. Why write another one by yourself .. O (partition _ partition) o...

Let's use jquery here .. Jquery's Ajax is super simple .. A get function!

But a lot of guys with poor foundations .. I still cannot understand it .. No way .. Let's talk about the principle ..

Ajax vernacular ---> asynchronous transmission .. Is to obtain data without refreshing the page ..

Then, we use a function to get the data you need from a file ..

At this time, an event will appear .. What event Ni .. That is the loading event .. For example, click a button .. Run 1

Functions. This function obtains the data of a file .. At this time, the data volume is large. At this time, do you

Will wait for a while .. For example, 5 seconds .. After obtaining the data, you can display the data on the page .. This is why

They're starting again !! [Load completion event] That is to say, all your operations should be written here, such as displaying data .. What

..

So much .. In fact, this is to lead to the [load completion event]

Nothing else .. Next let's take a look at the actualCodeHow is it written .. It's really easy .. Happy!

Add the jquery class library to <Script language = "JavaScript" type = "text/JavaScript" src = "jquery-1.2.1.pack.js"> </SCRIPT>

Step 2 Write this Ajax function! Before that, Let me arrange the members of the body ..
<A href = "#" onclick = "javascript: O ();"> KKK </a>
<Div id = "PP"> 55 </div>
An onclick event of a and a div runs the O function .. Now let's write this O function !!
Function O (){
$. Get (
"Peng.txt ",
Function (data ){
$ ("# Pp" ).html (data );
}
);
}
Peng.txt is the file for getting data. It can be any Web file ..
Function (data) is the [load completion event] mentioned above, and data is the data obtained ..
$ ("# Pp" ).html (data); this is the body of the function we are executing .. It is equivalent to document. getelementbyid ("PP"). innerhtml = data;
The syntax is different .. It means the same .. Simple .. Roar ..

The last tip is: utf8 .. The encoding of peng.txt

Code download

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.