【发布时间】:2017-11-26 17:13:19
【问题描述】:
解析xml使用ajax时遇到问题。似乎看不出这里出了什么问题,因为我已经能够在我的代码中使用 ajaxelsewhere 检索 API。任何帮助将不胜感激。
html:
<div id="technology" class="tab-pane fade">
<h3>TECH</h3>
<p id="tech_news"></p>
</div>
$(document).ready(function() {
$.ajax({
type: "GET",
url: "http://feeds.bbci.co.uk/news/technology/rss.xml",
dataType: "xml",
cache: false,
success: parseXml
});
});
function parseXml(xml) {
$(xml).find("item").each(function() {
$("#tech_news").append($(this).find("title").text() + "<p>");
$("#tech_news").append($(this).find("description").text() + "<p>");
});
}
【问题讨论】:
-
你能分享一下回复吗
xml -
@MuhammadOmerAslam 我不确定你的意思是什么?对不起。
-
你指定了
dataType:"XML",这意味着它返回一个可以通过jQuery处理的XML文档。我说的是那个回复文件 -
@MuhammadOmerAslam XML 文件在上面的 url 中指定。它是来自新闻网站的 RSS 提要。
-
无法加载feeds.bbci.co.uk/news/technology/rss.xml?_=1511718738881:
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access。
标签: xml ajax ajax html jquery jquery ajax xml twitter-bootstrap