$ (function () {
$ ("#Button1"). Click (function () {//button clicking Event
Open the file and process the retrieved data through the callback function
$.get ("Userinfo.xml", function (data) {
$ ("#divTip"). empty (); Clear the contents of the tag first
var strhtml = ""; Initialize the Save content variable
$ (data). Find ("User"). each (function () {//traverse the retrieved data
var $strUser = $ (this);
strHTML + = "Name:" + $strUser. Find ("name"). Text () + "<br>";
strHTML + = "Gender:" + $strUser. Find ("Sex"). Text () + "<br>";
strHTML + = "Mailbox:" + $strUser. Find ("email"). Text () + " })
$ ("#divTip"). HTML (strhtml); Show the processed data
})
})
$ (document). Ready (function () {
$ (' #button '). Click (function () {
$.ajax ({
var data={name:name,password:pass,uname:uname,......};
Type: "Get",
URL: "File.txt",
URL: "http://115.28.175.148/test/geItemLlist.php",
Data: ",
JSONP: ' Callback ',
DataType: "JSON",
Success:function (data) {
alert (data);
var obj=eval (data);
var file= "<ul>";
I represents the index position in data, and N represents the object containing the information
$.each (Obj,function (i,n) {
file+= "<li>" + "filename" +n["block_name"]+ "URL:" +n["Block_url"]+ "file description" + n["Block_desc"]+ "<a href= ' # ' >" + "Download" + "</a>" + "</li>";
});
file+= "</ul>";
$ (' #result '). Empty (). append (file);
},
Error:function () {
Alert (' Error ');
}
});
return false;
});
$ ("#xmlclick"). Click (function () {
$ ("#xmlcontent"). html (');
Alert ("AAAA");
$.ajax ({
Type: "GET",
URL: "C:\Users\Administrator\Downloads.xml\12_12 (1). xml",
DataType: "xml",
Error:function () {
Alert (' Error ');
// },
Success:function (responsetext) {
alert (responsetext);
var table = "<table border= ' 1px ' ><tr><td>firstname</td><td>lastname</td>< Td>city</td></tr> ";
$ (responsetext). Find (' friend '). each (function () {
var first = $ (this). Find (' FirstName '). Text ();
var last = $ (this). Find (' LastName '). Text ();
var city = $ (this). Find (' city '). Text ();
Table + = "<tr><td>" + First + "</td><td>" + Last + "</td><td>" + City + "</td> ;</tr> ";
// })
Table + = "</table>";
$ ("#message"). Append (table);
alert (responsetext);
// }
// });
// });
});
jquery Ajax gets local JSON as well as XML files