JQuery is a very powerful class library. I learned about it today and fell in love with it. Let's talk about how to use ajax in jQuery.
Example:
Test.html
Page reference <script type = "text/javascript" src = "jquery-1.3.2.min.js"> </script>
Content:
<Div id = "divMsg"> Hello World! </Div>
Usage 1: (the remote page content is read to divMsg when the page is loaded)
$ ("# DivMsg"). load (http: // localhost: 8012/t. asp, {"resultType": "html "});
The returned type resultType is as follows:
"Xml", "html", "script", "json", "jsonp", "text"
Usage 2: (Click post to return data)
<Input type = "button" id = "bnajax" value = "ajax" onclick = "ajaxTest ()"/>
<Script type = "text/javascript">
Function ajaxTest ()
{
$. Post ("http: // localhost: 8012/t. asp", {"txt": "123"}, function (data)
{
$ ("# DivMsg" pai.html (data );
}
);
}
</Script>
The following are functions taken from the network:
The post method is as follows:
Function test (access_url, tipE ){
$. Post (access_url ,{
First: "test1", second: "test2"
}, Function (data ){
If (data. success ){
$ ('#' + TipE).html ('processed successfully ');
} Else {
$ ('#' + TipE).html (data. msg );
}
}, 'Json'
)
}
If you want to use the get method, you can replace post with get, which is quite simple!
The data value in this function is the value returned by the server in JSON format. Of course, other types such as text and xml can be used here.
The return value on the server is in JSON format, for example, {success: true, msg: "tested "}