由于要做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>

解决方案 »

  1.   

    $(document).ready(function(){
      //Jquery函数。页面加载完成才执行的函数
    })
      

  2.   

    这个你要看google map的API了。在ajax请求的时候设置的 ~
      

  3.   


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

  4.   

    <body onunload="OnLoad();">
      

  5.   

    通过xmlHttpRequest对像来判断页面进行的状态,当xmlHttpRequest.readyState==4&&xmlHttpRequest.status=200的时候你再做循环操作!