I am building my own personalweb (and my first webpage) and I'm having some troubles trying to display a google map.
First of all, I will try to explain my case. my webpage has four links that load the HTML code of each section inside a div. Because of i dont want to refresh my webpage everytime a link is clicked, That HTML code is recieved through an AJAX request. When a section called 'contact me' is clicked, i call the initialize method to load the map inside a div that has been created in the new HTML code recieved via AJAX. Of course I call initialize after the HTML code is recieved.
Everything seems to work fine, but it only does when I click the link for the first time. When I do, I can see the map; but when I go to another section and then I click again on 'contact me' I see the div but the map is gone:
http://s8.postimg.org/9rllxtxed/map_error.jpg // I dont have enough reputation yet to post images.
This is the initialize function:
function initialize() {
var target_div = document.getElementById("map"); //This is the ID of the div created on the HTML code recieved through AJAX.
var mapOptions = {
center: new google.maps.LatLng(65.6516152,-34.7739923),
zoom: 12,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(target_div,mapOptions); //*map* is a global variable (one of my many tries to resolve it)
}
And this is the function that calls AJAX requests and initialize to display the content in a div called reciever_div:
function open_section(clicked_link) {
if (actual_link != null){
actual_link = clicked_link;
reciever_div.fadeOut(750,function(){
reciever_div.html('');
$.ajax({
url: 'textos/'+clicked_link+'.txt',
success: function (recieved_file) {
reciever_div.html(recieved_file);
if (clicked_link == 'contactme') {
initialize();
}
reciever_div.fadeIn(750);
}
});
});
}
else{
actual_link = clicked_link;
$.ajax({
url: 'textos/'+ clicked_link + '.txt',
success: function(recieved_file){
reciever_div.html(recieved_file);
if (clicked_link == 'contactme') {
console.log(clicked_link);
initialize();
}
reciever_div.fadeIn(1500);
}
})
}
}
Do you know why is this happening, or a better way to implement this? I'm a noob, and i dont know if i'm asking too much to ajax requests, css or what.
thanks a lot!