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