2012-01-03 230 views
0

我想加载谷歌地图与jQuery的 逻辑文件是很容易的,我想的是,页面重新加载每当我发送一个新的变数查询时间...jQuery的负荷谷歌地图

的问题是内容不加载..

这里是代码的JavaScript ....

<script type="text/javascript"> 
$(document).ready(function(){ 
function Display_Load() 
{ 
    $("#loading").fadeIn(900,0); 
    $("#loading").html("<img src='img/bigLoader.gif' style='border:none;' />"); 
} 
//Hide Loading Image 
function Hide_Load() 
{ 
    $("#loading").fadeOut('slow'); 
}; 
$("#pagination li").click(function(){ 
Display_Load(); 
$("#content").load("file_map.php", Hide_Load()); 
} 
}); 
</script> 

,这里的HTML代码

<body> 
<div id="loading" ></div> 
<div id="content" ></div> 
    </body> 

本例是与其他文件PHP或HTML,但只是还没有与谷歌地图的工作,我认为这个问题是在初始化()函数在页面加载,但我不工作得很好知道如何解决它,请谁可以帮我

th'x很多

回答

0

有没有在你的JavaScript代码中的错误,你有没有完成click调用(或ready通话;语法错误的本质意味着我们不知道哪一个是不完整的)。因此,没有任何代码正在运行,您应该会在JavaScript控制台中看到语法错误。

使用正确的缩进可以帮助您发现错误,这非常值得养成这样做的习惯。这是你的代码的正确缩进版本:

<script type="text/javascript"> 
$(document).ready(function(){ 
    function Display_Load() 
    { 
     $("#loading").fadeIn(900,0); 
     $("#loading").html("<img src='img/bigLoader.gif' style='border:none;' />"); 
    } 
    //Hide Loading Image 
    function Hide_Load() 
    { 
     $("#loading").fadeOut('slow'); 
    }; 
    $("#pagination li").click(function(){ 
     Display_Load(); 
     $("#content").load("file_map.php", Hide_Load()); 
    } 
}); 
</script> 

如你(现在)看,你错过了第二至最后一行);完成click通话。

一旦你解决这个问题,分别有一个错误在这条线:

$("#content").load("file_map.php", Hide_Load()); 
//        here -----^^ 

就像任何其他函数调用,还有你调用Hide_Load并通过其返回值load。如果你想Hide_Load是完成回调,你不想呼叫它,你只是想通过函数引用  —沟()

$("#content").load("file_map.php", Hide_Load); 

随着(),这就像你”因为对不使用return的函数的函数调用的结果是undefined,所以重新调用$("#content").load("file_map.php", undefined);

+0

地图内容我已经尽量不要使用Hide_Load()函数,但同样的错误仍然会出现 – Boumaili 2012-01-03 15:11:12

+0

@Boumaili:这里面有我的答案已经指出的另一个问题;你一定已经阅读了一个陈旧的答案。 – 2012-01-03 15:11:38

0

这里谷歌地图file_map.php的为例文件的内容.....

<?php include_once($_SERVER['DOCUMENT_ROOT'] . "/config.php"); 
require_once($lib_path."mysql.class.php"); 
require_once($lib_path."document.php"); 
require_once $lib_path . "userAccount.php"; 
require_once($lib_path."adsearch_class.php"); 
?> 


<!DOCTYPE html "-//W3C//DTD XHTML 1.0 Strict//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/> 
    <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=------------------------------------" type="text/javascript"></script> 

<script type="text/javascript"> 

function initialize() { 
    if (GBrowserIsCompatible()) { 
    var map = new GMap2(document.getElementById("map_canvas")); 
    map.setCenter(new GLatLng(37.4419, -122.1419), 13); 
    map.setUIToDefault(); 
    } 
} 

</script> 


</head> 
    <body onload="initialize()" onunload="GUnload()"> 
    <div id="map_canvas" style="width: 500px; height: 300px"></div> 
    </body> 
</html> 

这个文件是工作良好,没有jQuery的... ,但没有结果,当我与jQuery的调用它..

该索引。PHP文件是在这里

<?php 
include_once($_SERVER['DOCUMENT_ROOT'] . "/config.php"); 
require_once($lib_path."mysql.class.php"); 
require_once($lib_path."document.php"); 
require_once $lib_path . "userAccount.php"; 
require_once($lib_path."adsearch_class.php"); 

$per_page = 5; 

//getting number of rows and calculating no of pages 
$rsd=new db_publish; 
$rsd->connect(); 
$sql = "SELECT *FROM `table` LIMIT 0 , 30"; 
$rsd->query($sql); 
$counteur = $rsd->count(); 
$pages = ceil($counteur/$per_page); 
?> 


    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/ 
libs/jquery/1.3.0/jquery.min.js"></script> 
    <script type="text/javascript"> 

    $(document).ready(function(){ 

    //Display Loading Image 
    function Display_Load() 
    { 
     $("#loading").fadeIn(900,0); 
     $("#loading").html("<img src='img/bigLoader.gif' />"); 
    } 
    //Hide Loading Image 
    function Hide_Load() 
    { 
     $("#loading").fadeOut('slow'); 
    }; 


    //Default Starting Page Results 

    $("#pagination li:first").css({'color' : '#FF0084'}).css({'border' : 'none'}); 

    Display_Load(); 

    $("#content").load("file_map.php"); 



    //Pagination Click 
    $("#pagination li").click(function(){ 

     Display_Load(); 

     //CSS Styles 
     $("#pagination li") 
     .css({'border' : 'solid #dddddd 1px'}) 
     .css({'color' : '#0063DC'}); 

     $(this) 
     .css({'color' : '#FF0084'}) 
     .css({'border' : 'none'}); 

     //Loading Data 
     var pageNum = this.("#pagination li").id; 

     $("#content").load("file_map.php?page=" + pageNum); 
    }); 


}); 
    </script> 

<style> 
body { margin: 0; padding: 0; font-family:Verdana; font-size:15px } 
a 
{ 
text-decoration:none; 
color:#B2b2b2; 

} 

a:hover 
{ 

color:#DF3D82; 
text-decoration:underline; 

} 
#loading { 
width: 100%; 
position: absolute; 
} 

#pagination 
{ 
text-align:center; 
margin-left:120px; 

} 
li{ 
list-style: none; 
float: left; 
margin-right: 16px; 
padding:5px; 
border:solid 1px #dddddd; 
color:#0063DC; 
} 
li:hover 
{ 
color:#FF0084; 
cursor: pointer; 
} 


</style> 


    <div align="center"> 


    <div id="loading" ></div> 
    <div id="content" ></div> 


    <table width="800px"> 
    <tr><Td> 
      <ul id="pagination"> 
       <?php 
       //Show page links 
       for($i=1; $i<=$pages; $i++) 
       { 
        echo '<li id="'.$i.'">'.$i.'</li>'; 
       } 
       ?> 
    </ul> 
    </Td></tr></table> 
    </div> 

,我告诉你,第一时间本例是结果页面我刚才

<div id="map_canvas" style="width: 500px; height: 300px"></div> 
上工作也只是与谷歌地图的内容无法加载....

没有内部