views:

130

answers:

2

i just got my first ever stack overflow when I ran this script:

var hlat = 0.00;
var hlong = 0.00;
var mapdiv = document.getElementById('map');
var map_url = base_url + 'ajax/getPropMap';
var id_url = base_url + 'hotels/gethotel_id';
var id=0;
var map = null;
// apply gmaps to product map div

$(function(){
    $.get(id_url, {id: segment}, getMapDetails);
});

function getMapDetails(data){
    $.getJSON(map_url, {id:data}, addToProdMap);
}

function getMapDetails(data){
    addProdMap(data);
}

function addProdMap(data){
    hlat = data.latitude;
    hlong = data.longitude;

    map = new google.maps.Map(mapdiv, {
            center : new google.maps.LatLng(hlat, hlong),
            zoom : 13,
            mapTypeId : 'hybrid'
    });

    var coords = new google.maps.LatLng(hlat, hlong);
    var marker = new google.maps.Marker({
        clickable : true,
        map: map,
        icon : 'http://labs.google.com/ridefinder/images/mm_20_red.png',
        position : coords
    })
}

How do I deal with this? Firefox closes and IE displays the stack overflow error

A: 

Step 1: Upgrade to the latest Firefox

Step 2: Install Firebug

Step 3: After those two steps Firefox should no longer crash when you try and run that script. If it does, try wrapping the whole thing in a try/catch and log the exception which gets caught. If it doesn't crash, the exception should just be logged to your Firebug console as normal (assuming you have it turned on).

Step 4: Now that you've actually got an exception you can look at, just follow the stacktrace to see what line in particular is causing the problem.

Hope that works (but if not comment back).

machineghost
A: 

You have two functions of the same name: getMapDetails

Josh Stodola
that duplicate function name is the problem, the line you higlight is a function that triggers on page load, trying to retrieve a session variable from the server...so, I guess I'll choose your answer
Ygam
Yes, if you comment that line out I don't think you will get the error (because that is when the function in question actually gets invoked). I updated my answer.
Josh Stodola