jQuery .ajax map within div

296 views
Skip to first unread message

Jas

unread,
Mar 28, 2011, 10:55:24 AM3/28/11
to Google Maps JavaScript API v3
I have been searching for an answer to this but have not been able to
find one suitable for the situation.

What I am trying to accomplish is to use an onClick event to load html
data via jQuery's .ajax() function within a specified div.

The requested html data contains a map element displaying their
computer location. I understand the limitations of the http protocol
as a stateless procedure does not execute the newly loaded html data
and its associated javascript functions (in this case the google maps
api), without being told to do so.

I am sure someone has come across this and I would would like to know
how it was over come.

Here is what I am working with

<script type="text/javascript" src="http://maps.google.com/maps/api/js?
sensor=true"></script>

<script type="text/javascript">
var $j = jQuery.noConflict();
$j(document).ready(function(){

$j('#reg').click(function(){
$loadModules('register', 'register.html');
});

function $loadModules($key, $value){
$j.ajax({
url:'proxy.php',
type:'post',
data:'module='+$value,
context:$j('#'+$key),
dataType:'html',
success: function($response){
$j('#'+$key).html($response);
$initialize();
}
});
return false;
}

function $initialize(){
var myLatlng = new google.maps.LatLng(-34.397, 150.644);
var myOptions = {
zoom: 8,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById('map'),
myOptions);
}
});
</script>

Chris Broadfoot

unread,
Mar 29, 2011, 3:54:24 AM3/29/11
to google-map...@googlegroups.com, Jas
As per forum guidelines, can you please post a link to your map?

Jason Gerfen

unread,
Mar 29, 2011, 5:46:56 AM3/29/11
to Chris Broadfoot, google-map...@googlegroups.com
Whoops. http://cerberus.in-my-cloud.com/

Once the modules load click the 'sign up here' link. It uses .ajax to
load into a div which is where the map should be.

--
Jas

Reply all
Reply to author
Forward
0 new messages