php phonegap,php – 使用Phonegap应用程序执行ajax请求的问题

我正在尝试使用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

?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值