admin管理员组文章数量:1418669
I'm using the Google AJAX Feed API to search for a RSS feed. It works when I just run the javascript in the head of my HTML document in EXAMPLE 1 below (I know I'm getting no result, but that's a problem for another day!), but I need to actually run it when everything's loaded. I'm using jquery, so I've got a $(window).load(function(){}); method, but it doesn't work when I run the Google code in there (EXAMPLE 2). Can anyone see what I'm doing wrong?
EXAMPLE 1 - index.html
<head>
<script type="text/javascript">
console.debug("before google load code");
google.load("feeds", "1");
console.debug("after google load code");
google.setOnLoadCallback(loaded);
function loaded() {
console.debug("google loaded");
google.feeds.findFeeds("news", feedSearchDone);
}
function feedSearchDone(result) {
if (result.error || result.entries.length <= 0) {
console.debug("No Results Found");
return;
}
else {
console.debug(result.entries[0].url);
} }
</script>
</head>
EXAMPLE 1 - code.js
$(window).load(function() {
console.debug("in jquery load function");
});
EXAMPLE 1 - output in Firebug:
before google load code
after google load code
in jquery load function
google loaded
No Results Found
EXAMPLE 2 - code.js
$(window).load(function() {
console.debug("in jquery load function");
console.debug("before google load code");
google.load("feeds", "1");
console.debug("after google load code");
google.setOnLoadCallback(loaded);
function loaded() {
console.debug("google loaded");
google.feeds.findFeeds("news", feedSearchDone);
}
function feedSearchDone(result) {
if (result.error || result.entries.length <= 0) {
console.debug("No Results Found");
return;
}
else {
console.debug(result.entries[0].url);
} }
});
EXAMPLE 2 - output in Firebug
in jquery load function
before google load code
window.loadFirebugConsole is not a function
[Break on this error] <html lang="en">
Even though the error refers to Firebug, I don't think that's the cause because it the page behaves the same (no elements are on the screen) when I view it in Safari. Thanks for reading.
I'm using the Google AJAX Feed API to search for a RSS feed. It works when I just run the javascript in the head of my HTML document in EXAMPLE 1 below (I know I'm getting no result, but that's a problem for another day!), but I need to actually run it when everything's loaded. I'm using jquery, so I've got a $(window).load(function(){}); method, but it doesn't work when I run the Google code in there (EXAMPLE 2). Can anyone see what I'm doing wrong?
EXAMPLE 1 - index.html
<head>
<script type="text/javascript">
console.debug("before google load code");
google.load("feeds", "1");
console.debug("after google load code");
google.setOnLoadCallback(loaded);
function loaded() {
console.debug("google loaded");
google.feeds.findFeeds("news", feedSearchDone);
}
function feedSearchDone(result) {
if (result.error || result.entries.length <= 0) {
console.debug("No Results Found");
return;
}
else {
console.debug(result.entries[0].url);
} }
</script>
</head>
EXAMPLE 1 - code.js
$(window).load(function() {
console.debug("in jquery load function");
});
EXAMPLE 1 - output in Firebug:
before google load code
after google load code
in jquery load function
google loaded
No Results Found
EXAMPLE 2 - code.js
$(window).load(function() {
console.debug("in jquery load function");
console.debug("before google load code");
google.load("feeds", "1");
console.debug("after google load code");
google.setOnLoadCallback(loaded);
function loaded() {
console.debug("google loaded");
google.feeds.findFeeds("news", feedSearchDone);
}
function feedSearchDone(result) {
if (result.error || result.entries.length <= 0) {
console.debug("No Results Found");
return;
}
else {
console.debug(result.entries[0].url);
} }
});
EXAMPLE 2 - output in Firebug
in jquery load function
before google load code
window.loadFirebugConsole is not a function
[Break on this error] <html lang="en">
Even though the error refers to Firebug, I don't think that's the cause because it the page behaves the same (no elements are on the screen) when I view it in Safari. Thanks for reading.
Share Improve this question asked Jun 21, 2010 at 6:20 benben 29.8k42 gold badges128 silver badges182 bronze badges4 Answers
Reset to default 3 +100The JQuery onload can ONLY be used after the google onLoad callback.
function initialize() {
$(function () {
// Some other code here
});
}
google.setOnLoadCallback(initialize);
Try adding that to the code.js file.
You have to use $(document).ready
instead, the scripts will only load after the DOMLoad pletes.
Are you definitely including jquery above your $ doc.ready?
In stead of using google.load the google Libraries API states:
The preferred method is to load the libraries via standard tags (as in <script src="https://ajax.googleapis./ajax/libs/jquery/1.4.2/jquery.min.js"></script>
, which will result in the fastest loads.
The nice thing about this is that you don't need to set google.setOnLoadCallback and the libraries are available at page load anyway.
本文标签: javascriptgoogleload not working when run in jquery39s (window)load(function())Stack Overflow
版权声明:本文标题:javascript - google.load not working when run in jquery's $(window).load(function(){});? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745291230a2651808.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论