由于白名单安全性,我使用PHP脚本从外部服务器返回XML。
PHP文件代码如下所示 -
<?php
include_once 'utilityCurl.class.php';
$uri = 'http://OURSERVER/feeds/?feedID=99&c';
$response = utilityCurl::fetchContent($uri);
echo $response;
它使用curl返回xml文件。
然后我使用jQuery ajax xml脚本来解析 -
$.ajax({
type: "GET",
url: "http://fb.mobilechilli.com/chilli_news_reviews/news_feed_retrival.php",
dataType: "xml",
success: parseXml,
error: errorMsg
});
//Once xml parsed and entered onto page - run caroufred class that makes the carousel work.
function parseXml(xml)
{
$(xml).find("NewsItem").each(function()
{
var title = $(this).find('HeadLine').text();
var artist = $(this).find('NewsLineType').text();
var listItem = $('<p>hello '+title+'</p><p>'+artist+'</p><br/>');
$(".newsHeader").append(listItem);
});
alert("yep");
}
function errorMsg() {
alert("error getting xml feed");
}
});
不幸的是我只是显示错误信息!
有人可以告诉我哪里错了吗?
由于 保罗
答案 0 :(得分:1)
json在这里工作会更容易。
在php转储中而不是
echo json_encode(simplexml_load_string($xml));
然后在javascript中你可以检查json.NewsItem是否填充了什么