jquery Ajax gets local JSON as well as XML files

Source: Internet
Author: User

$ (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&gt ;</tr> ";
// })
Table + = "</table>";
$ ("#message"). Append (table);
alert (responsetext);
// }
// });
// });

});

jquery Ajax gets local JSON as well as XML files

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.