2
我試圖解析一些XML數據在一個基本的網頁顯示找到。 XML如下:使用JQuery解析XML,需要通過屬性名稱
<response>
<variable name = "Input1">False</variable>
<variable name = "Input2">False</variable>
<variable name = "Input3">False</variable>
<variable name = "Input4">False</variable>
<variable name = "Input5">False</variable>
<variable name = "Input6">False</variable>
<variable name = "Input7">False</variable>
<variable name = "Input8">False</variable>
</response>
我有一些代碼是顯示,但目前我得到所有8個變量顯示在1個文本區域。
$(document).ready(function()
{
$.ajax({
type: "GET",
//To change controller, please chnage the IP below.
url: "http://172.20.2.17/query/variable?Input1&Input2&Input3&Input4&Input5&Input6&Input7&Input8",
dataType: "xml",
success: parseSystem
});
})
//Parse System XML Response
function parseSystem(xml)
{
$(xml).find("response").each(function()
{
$("#Input1").append($(this).find("variable").text())
$("#Input2").append($(this).find("variable").text())
$("#Input3").append($(this).find("variable").text())
$("#Input4").append($(this).find("variable").text())
$("#Input5").append($(this).find("variable").text())
$("#Input6").append($(this).find("variable").text())
$("#Input7").append($(this).find("variable").text())
$("#Input8").append($(this).find("variable").text())
});
我想要的是在XML中的Input1鏈接到HTML中的#Input1等等。
謝謝您的時間,它是真正的讚賞。
則可以重複使用'$(本)',而不是執行兩次:) – 2011-03-11 06:26:04