views:

465

answers:

2

I am trying to load WalkScore Map into one of div's on the page. For some reason my code works only if I alert() something right after $.get() method. Have no idea why.

Can someone suggest something? Thanks.


<html>

jQuery - Ajax dynamic content loading

function loadWalkScore() 
{
 $.get("http://www.walkscore.com/tile/show-tile.php?wsid=567f19156a706dddb8a799630d85467e",null,null,"script");
 alert("hello");
}

</script>

<div id="contentArea" style="margin: 20px 0px 10px 10px; border: 1px solid #CCC;">

<script type="text/javascript">
 var ws_lat = "40.710318";
 var ws_lon = "-74.016553";
 var ws_width = "630";
 loadWalkScore();
</script>


</div>

A: 

For me is working. I had to change the wsid for my domain. I've checked the get request using Firebug and I get a javascript as a response. At the begining I was getting an error because I was using you wsid and it seems that for each calling sides they generate a new one. Try to see if your wsid is the correct one.

Elzo Valugi
Hello Elzo,What browsers do you use (except FF)? I uploaded two examples here:http://websvit.com/tabs/no-alert.html // doesn't workhttp://websvit.com/tabs/with-alert.html // works here
in FF is working, even the one that you say is not. If is a browser issue I dont think is jQuery related.
Elzo Valugi
+1  A: 

Try using something like this, to make the call when the DOM is ready.

<script type="text/javascript">
$(function()
{
$.get("http://www.walkscore.com/tile/show-tile.php?wsid=567f19156a706dddb8a799630d85467e",null,null,"script");
});
</script>

Put this block after your first <script> element.

Peter
Hi Peter,It still doesn't work for me. The page is loading indefinitely in FF 3 and IExplorer 8. I also tried using $(document).ready(function(), see code below: <script type="text/javascript"> $(document).ready(function(){ var ws_lat = "40.710318"; var ws_lon = "-74.016553"; var ws_width = "630"; $.get("http://www.walkscore.com/tile/show-tile.php?wsid=567f19156a706dddb8a799630d85467e",null,null,"script"); }); </script>