从PHP函数JSON数据我想将数据从一个PHP函数来发送使用AJAX我的HTML网页,我的功能看起来像:获取使用AJAX
function getFeed() {
$url = 'http://feeds.bbci.co.uk/news/rss.xml?edition=int#';
$content = file_get_contents($url);
$data = simplexml_load_string($content);
$articles= array();
foreach($data->channel->item as $item){
$articles[]=array(
'title' => (string)$item->title,
'description' => (string)$item->description,
'link' => (string)$item->link,
'Date' => (string)$item->pubDate,
);
}
foreach($articles as $article){
echo json_encode($article['title']);
}
}
我的javascript脚本的样子:
$(function(){
$.ajax({
type:'GET',
url: '/rss/core/inc/rssnews.inc.php',
success: function (data){
console.log('success',data);
}
});
});
一旦我执行代码,我会在控制台中收到'success'
消息,但不会收到数据。 那么,在这种情况下如何获取JSON数据呢?如果你想看到所有的JSON的
你确定你定义后调用'getFeed'? – hassan
无需编码每个项目。只是'json_encode($ articles)' –
@HassanAhmed我不叫它,我应该怎么做我的JavaScript脚本 –