Jquery 如何使用XML Web服务?
我使用以下jQueryAjax方法来使用基于xml的Web服务,请同时查找jQuery代码。但我无法获取数据。类似的代码适用于jsonp,但不适用于xml。我错过了什么Jquery 如何使用XML Web服务?,jquery,Jquery,我使用以下jQueryAjax方法来使用基于xml的Web服务,请同时查找jQuery代码。但我无法获取数据。类似的代码适用于jsonp,但不适用于xml。我错过了什么 <script src="https://code.jquery.com/jquery-2.1.4.min.js"></script> <script> $(document).ready(function () { $('#myButton').click(function
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script>
$(document).ready(function () {
$('#myButton').click(function () {
var artistURL = "http://www.thomas-bayer.com/sqlrest/CUSTOMER/0/";
$.ajax({
type: "GET",
dataType: "xml",
url: artistURL,
success: function (data) {
$(data).find("CUSTOMER").each(function () {
$(this).find("FIRSTNAME").each(function () {
$("#semi").text($(this).text());
});
});
}
});
});
})
</script>
</head>
<body>
<button id="myButton"> Click Me</button>
<p id="semi"></p>
</body>
</html>
更新:本地副本可以在chrome上使用,但不能在mozilla中使用。
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script>
$(document).ready(function () {
$('#myButton').click(function () {
var artistURL = "http://www.thomas-bayer.com/sqlrest/CUSTOMER/0/";
$.ajax({
type: "GET",
dataType: "xml",
url: artistURL,
success: function (data) {
$(data).find("CUSTOMER").each(function () {
$(this).find("FIRSTNAME").each(function () {
$("#semi").text($(this).text());
});
});
}
});
});
})
</script>
</head>
<body>
<button id="myButton"> Click Me</button>
<p id="semi"></p>
</body>
</html>
无法获取xml格式是否有多个$semi元素给定的代码应该可以工作。。。除非你能提供更多细节,否则我想我们不能提供太多help@ArunPJohny我已经更新了一个公共xml文档,这是一个跨域问题还是您能够获取xml文档?