我正在尝试将外部XML URL的内容提取到javascript的ajax脚本中,但由于CROSS域问题,它根本不会接受它。我已经通过谷歌搜索了这个问题,但到目前为止没有什么好处,到目前为止我所读到的所有内容都表明我需要整合PHP,但有了这个,页面就会重新加载。
我只是希望当用户输入一个数字时,该数字作为URL中的参数传递,然后在屏幕上显示XML内容而不重新加载。
所以任何帮助都将受到高度赞赏。
到目前为止,这是我的代码。
<script>
function myFunction() {
$("#dvContent").append("<ul></ul>");
$.ajax({
type: "GET",
url: "http://lx2.loc.gov:210/lcdb?operation=searchRetrieve&recordSchema=marcxml&version=1.1&maximumRecords=1&query=bath.isbn%3D9781452110103",
dataType: "xml",
success: function(xml){
$(xml).find('record').each(function(){
var sTitle = $(this).find('datafield[tag="245"]').find('subfield[code="a"]').text();
var sAuthor = $(this).find('datafield[tag="100"]').find('subfield[code="a"]').text();
var sIsbn = $(this).find('datafield[tag="020"]').find('subfield[code="a"]').text();
$(".mypanel").html(text);
});
$("<li></li>").html(sTitle).appendTo("#dvContent ul");
$("<li></li>").html(sAuthor).appendTo("#dvContent ul");
$("<li></li>").html(sIsbn).appendTo("#dvContent ul");
});
},
error: function() {
alert("An error occurred while processing XML file.");
}
});
}
</script>