Example:
Test.html
Page reference <script type= "Text/javascript" src= "Jquery-1.3.2.min.js" ></script>
The contents are:
<div id= "divmsg" >hello world!</div>
Usage 1: (Read the remote page content on page load to divmsg)
$ ("#divMsg"). Load (http://localhost:8012/t.php, {"Resulttype": "html"});
The return type Resulttype has the following kinds:
"XML", "HTML", "script", "JSON", "Jsonp", "text"
Usage 2: (click Post data to return data)
Copy Code code as follows:
<input type= "button" id= "Bnajax" value= "Ajax" onclick= "Ajaxtest ()"/>
<script type= "Text/javascript" >
function Ajaxtest ()
{
$.post ("http://localhost:8012/t.php", {"TXT": "123"},function (data)
{
$ ("#divMsg"). HTML (data);
}
);
}
</script>
The following are the functions that are excerpted from the network:
The Post method is as follows:
Copy Code code as follows:
function test (Access_url, tipe) {
$.post (access_url,{
A: "Test1", Second: "Test2"
}, function (data) {
if (data.success) {
$ (' # ' + tipe). HTML (' process success ');
}else{
$ (' # ' + tipe). HTML (DATA.MSG);
}
}, ' JSON '
)
}
If you want to use the Get method, then put the post for get is OK, quite simple!
The data value in this function is the value returned by the server and is in JSON format, and of course, there are other types, such as Text,xml and so on.
The service-side return value is in JSON format, such as: {success:true, msg: "Test succeeded"}