请教一个 js 里面循环的问题

逍遥散人 2010-10-22 02:09:03
由于要做google ajax search api的开发,但是由于查询量太大,想测试一下超过1000后GOOGLE的反应是什么?因此在google的范例中增加了一个for语句,现在的问题是,每次都没来得及打开网页就自动循环到下一步了,而且,循环到600多的时候浏览器就假死状态了.....
想请教一下,在js中如何才能做到,判断页面加载完成后才继续往下循环?(这是公司的项目,因此,谷歌的 license key就不提供了,见谅)

附:google的示例代码:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Hello World - Google AJAX Search API Sample</title>

<style type="text/css">

body {
background-color: white;
color: black;
font-family: Arial, sans-serif;
font-size : 13px;
margin: 15px;
}

#searchcontrol .gsc-control { width : 400px; }


</style>
<!-- Replace with http://www.google.com/jsapi -->
<script src="http://www.google.com.hk/jsapi?key=xxxxxx" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[

google.load('search', '1.0');

function OnLoad() {
// Create a search control
var searchControl = new google.search.SearchControl();

// Add in a full set of searchers
var localSearch = new google.search.LocalSearch();
searchControl.addSearcher(localSearch);
searchControl.addSearcher(new google.search.WebSearch());
searchControl.addSearcher(new google.search.VideoSearch());
searchControl.addSearcher(new google.search.BlogSearch());
searchControl.addSearcher(new google.search.NewsSearch());
searchControl.addSearcher(new google.search.ImageSearch());
searchControl.addSearcher(new google.search.BookSearch());
searchControl.addSearcher(new google.search.PatentSearch());

// Set the Local Search center point
//localSearch.setCenterPoint("New York, NY");

// tell the searcher to draw itself and tell it where to attach
searchControl.draw(document.getElementById("searchcontrol"));

// execute an inital search
searchControl.execute("北京联通");

}
google.setOnLoadCallback(OnLoad, true);

//]]>
</script>
</head>
<body>
<div id="searchcontrol">Loading</div>
</body>
</html>
...全文
120 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
zjhiphop2006 2010-10-23
  • 打赏
  • 举报
回复
通过xmlHttpRequest对像来判断页面进行的状态,当xmlHttpRequest.readyState==4&&xmlHttpRequest.status=200的时候你再做循环操作!
billlllyove 2010-10-23
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 zllking 的回复:]

JScript code

$(window).load(function() { alert(444) });//jquery代码
[/Quote]

++1
yuyejiewu 2010-10-22
  • 打赏
  • 举报
回复
<body onunload="OnLoad();">
zllking 2010-10-22
  • 打赏
  • 举报
回复

$(window).load(function() { alert(444) });//jquery代码
Mr-Jee 2010-10-22
  • 打赏
  • 举报
回复
这个你要看google map的API了。在ajax请求的时候设置的 ~
逍遥散人 2010-10-22
  • 打赏
  • 举报
回复
设置同步?咋设置啊?
Mr-Jee 2010-10-22
  • 打赏
  • 举报
回复
load的时候设置同步呗~~!
shaoliang520xi 2010-10-22
  • 打赏
  • 举报
回复
$(document).ready(function(){
//Jquery函数。页面加载完成才执行的函数
})

87,915

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧