Jquery each and Google API - Page is reloading, but why?
i have a little problem with the Google Feed API and jquery each.
The problem:
I get a reload when i click on the start button.
Can somebody explain me why?
HTML
<input type="button" onclick="tkk_rss_check();" value="start"/>
JS
$(document).ready(function trt()
{
tkk_rss = {};
tkk_rss['32'] = new Array("gulli:News", "http://ticker.gulli.com/rss", "0", "gulli:News", "0", "gle", "0");
tkk_rss['36'] = new Array("Golem.de", "http://rss.golem.de/rss.php?feed=RSS1.0", "155", "IT-News fuer Profis", "0", " ", "0");
tkk_rss['37'] = new Array("Heise", "http://www.heise.de/open/news/news-atom.xml", "156", "", "0", "", "0");
});
function tkk_rss_check()
{
$('body').append('Start<hr />');
google.load("feeds", "1");
$.each(tkk_rss开发者_如何学JAVA, function(i, val)
{
function initialize() {
var feed = new google.feeds.Feed(''+tkk_rss[i][1]+'');
feed.setNumEntries(10);
feed.load(function(result) {
if (!result.error) {
for (var i = 0; i < result.feed.entries.length; i++) {
var entry = result.feed.entries[i];
var attributes = ["title", "link", "publishedDate", "content", "contentSnippet"];
$('body').append(''+entry[attributes['0']]+' <br />');
}
}
});
}
google.setOnLoadCallback(initialize);
});
}
working example http://www.jsfiddle.net/V9Euk/587/
Thanks in advance! Peter
You need to suppress the button click, like this:
<input type="button" onclick="tkk_rss_check(); return false;" value="start"/>
精彩评论