我正在尝试使用Phonegap和jQuery创建一个简单的RSS阅读器.
我正在学习本教程:
http://visualrinse.com/2008/09/24/how-to-build-a-simple-rss-reader-with-jquery/.
当我在浏览器中试用代码时,我设法让这个工作得很好. PHP文件获取Feed并输出它就像我期望的那样.但是当我从我编译的Phonegap应用程序中运行相同的文件时,ajax-request只返回PHP文件的内容(PHP代码,而不是执行结果).
我花了几个小时谷歌搜索这个并尝试了很多教程和调整.我在官方的Phonegap论坛上找不到任何解决方案.我究竟做错了什么?问题似乎是PHP没有响应请求.我试图将PHP文件移动到另一个域,但结果是一样的,它在我的浏览器中工作,但不在编译的应用程序中.
这是启动ajax代码的jQuery代码:
function get_RSS_Feed() {
//clear the content in the div for the next Feed.
$("#Feed_content").empty().html('');
$.ajax({
url: 'http://192.168.1.7/RSSApp/www/RSS-proxy.PHP?url=http://www.nytimes.com/services/xml/RSS/nyt/GlobalHome.xml',success: function parseRSS(d) {
//find each 'item' in the file and parse it
$(d).find('item').each(function() {
//name the current found item this for this particular loop run
var $item = $(this);
// grab the post title
var title = $item.find('title').text();
// grab the post's URL
var link = $item.find('link').text();
// next,the description
var description = $item.find('description').text();
//don't forget the pubdate
var pubDate = $item.find('pubDate').text();
// now create a var 'html' to store the markup we're using to output the Feed to the browser window
var html = "
" + title + "";
html += "" + pubDate + "";
html += "
" + description + "
";html += "Read More >>";
//put that Feed content on the screen!
$('#Feed_content').append($(html));
});
$('#Feed_content img.loader').fadeOut();
}
});
};
这是RSS-proxy.PHP,它从url加载XML并输出:
// PHP Proxy
// Loads a XML from any location. Used with Flash/Flex apps to bypass security restrictions
// Author: Paulo Fierro
// January 29,2006
// usage: proxy.PHP?url=http://mysite.com/myxml.xml
$session = curl_init($_GET['url']); // Open the Curl session
curl_setopt($session,CURLOPT_HEADER,false); // Don't return HTTP headers
curl_setopt($session,CURLOPT_RETURNTRANSFER,true); // Do return the contents of the call
$xml = curl_exec($session); // Make the call
header("Content-Type: text/xml"); // Set the content type appropriately
echo $xml; // Spit out the xml
curl_close($session); // And close the session
?>