Jquery 讀取 xml
xml
<info>
<user>
<name>王小虎</name>
<sex>男</sex>
<habit>电脑游戏</habit>
</user>
<user>
<name>张小凡</name>
<sex>男</sex>
<habit>体育游戏</habit>
</user>
<user>
<name>卓不凡</name>
<sex>男</sex>
<habit>网球游戏</habit>
</user>
</info>
.ashx 檔案
string xml = "";
string str = "";
StreamReader file = new StreamReader(context.Server.MapPath("~/xml.txt")); //讀取xml字串
while ((str = file.ReadLine()) != null)
{
xml += str;
}
file.Close();
context.Response.ContentType = "text/xml";
context.Response.Write(xml);
.aspx檔案
var ajaxUrl = 'xmlRead.ashx';
$.ajax({
async: false,
type: 'POST',
url: ajaxUrl,
dataType: 'xml', //回船型態必須以xml
success: function (xml) { /*執行成功後接收回傳值*/
$(xml).find("info").children("user").each(function (i) {
var name_value = $(this).children("name").text();
var sex_value = $(this).children("value").text();
alert("姓名:" + name_value + " 性别:" + sex_value);
});
}
});
標籤: C#, Jquery Mobile
0 個意見:
張貼留言
訂閱 張貼留言 [Atom]
<< 首頁