您的位置:首页 > Web前端 > JQuery

关于nokia S40开发自带的jquery.jfeed.js

2012-01-29 16:01 155 查看
Nokia WDE新建一个项目的时候会自动带一个范例程序,读取一个RSS feed,然后展示出来。

今天研究了一下,发现RSS feed放在本地后就不好用了,只能读取远程服务器上的。这是为什么呢?

在网上找到了一个新的jquery.jfeed.js,貌似是比nokia包自带的那个更新,换过本身的jquery.jfeed.js就不存在本地还是远程的问题了,这是一个解决办法。

https://github.com/jfhovinne/jFeed/blob/master/build/dist/jquery.jfeed.js

1. 但是还是想研究一下为什么原来的那个不好用。打断点之后发现

console.log("xhr.status is " + xhr.status); 返回的xhr.status是0,而不是200。

搜索了一下找到解决办法是把本地xml文件放在localhost下
http://localhost/test/topstories.xml 代替xml/topstories.xml。这是第一个坑。

2. 这个改过之后发现xhr.status是200了但是还是读不出来feed,然后继续打log发现header的第一个参数是application/xml而不是text/xml,于是

if (arr[0].toLowerCase() == "application/xml") { 代替 if (arr[0].toLowerCase() == "text/xml") { 这是第二个坑。

补充一点关于application/xml和text/xml 的区别 /article/7026708.html,总的来说就是text/xml不支持UTF-8,所以我们基本上要用application/xml

3. 可是新的jquery.jfeed.js为什么不需要把xml放在本地也能解析呢?难道它没有用到XMLHttpRequest?

我想解决办法应该在jquery自己的$.ajax中,现在这个function我还没研究明白

继续。。

jquery.js 8165-8171行

// If the request is local and we have data: assume a success
// (success with no data won't get notified, that's the best we
// can do given current implementations)
console.log(!status + " " + s.isLocal + " " + !s.crossDomain);
if ( !status && s.isLocal && !s.crossDomain ) {
status = responses.text ? 200 : 404;
}


也就是说,相对路径的时候本来status是0,结果强制给status设置成200..
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: