我正在尝试从 webservice 获取一些 xml 数据。我可以访问所有数据,但无法一一获取。我想将数据写入 id 为“代码”的 div。它写[对象元素]。我必须做什么?
<script type="text/javascript">
$(document).ready(function () {
var returnValue = localStorage.getItem("returnValue");
var userName = localStorage.getItem("userName");
alert("Hello" + userName);
var wsUrl = "http://xxx=GetStocks";
var soapRequest =
'<?xml version="1.0" encoding="utf-8"?>\
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\ xmlns:xsd="http://www.w3.org/2001/XMLSchema"\ xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">\
<soap:Body>\
<GetStocks xmlns="http://sales.xxx.org/">\
<token>' + returnValue + '</token>\
</GetStocks>\
</soap:Body>\
</soap:Envelope>';
$.ajax({
type: "POST",
url: wsUrl,
contentType: "text/xml",
dataType: "xml",
data: soapRequest,
success: processSuccess,
error: processError
});
});
function processSuccess(data, status, req) {
if (status == "success") {
var stocks = $(req.responseXML).find("pStockInfo");
var codes = $(req.responseXML).find("Code");
var stocksCount = stocks.length;
$("#code").text(codes[0]); //Here i want first code.
}
}
function processError(data, status, req) {
alert(req.responseText + " " + status);
}
</script>
xml数据
我想获得第一个代码“FO19428”
你可以使用jQuery.eq()
var codes = $(req.responseXML).find("Code");
var firstCode = codes.eq(0).text();
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句