之前一直在用json来传递数据,但是xml也是不可缺少的,于是开始了xml的征程。xml的一些属性啊之类的在菜鸟教程上列举的已经很详细了,但是却没有前段部分的获取教程,查询资料,遂懂:
index.xml:
<?xml version="1.0" encoding="UTF-8"?> <note> <to>fangMing</to> <from>Tom</from> <heading>head</heading> <body> this is body </body> </note>
index.html:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <script src="http://cdn.bootcss.com/jquery/3.1.1/jquery.min.js"></script> </head> <body> </body> <script> $(() => { $.ajax({ method: "GET", url: "index.xml", dataType: "xml", success: (xmlDoc, textStatus) => { textStatus === "success"&&(console.log($(xmlDoc).find("to").text())); } }) }) </script> </html>
结果: