0

I use xhr objects get informations from mapquest open APIs (Nominatim and Directions).

My problem is that it works for the Nominatim service and it doesn't work for Directions (tested with Firefox last version). I get a readystate of 4 but a status of 0 and it never changes.

Here's my code :

var xhr;
try
{ 
 xhr = new ActiveXObject('Msxml2.XMLHTTP');
}
catch (e)
{
    try
    {  
        xhr = new ActiveXObject('Microsoft.XMLHTTP');
    }
    catch (e2)
    {
        try
        { 
            xhr = new XMLHttpRequest();
        }
        catch (e3)
        { 
            xhr = false;
        }
    }
}

xhr.onreadystatechange  = function()                                   
{                                     
    if(xhr.readyState  == 4)
    {
        if(xhr.status == 200)
        {
            alert(xhr.responseText);
        }
    }
};

xhr.open("GET", "http://open.mapquestapi.com/directions/v1/route?format=json&routeType="+routeType+"&timeType=0&enhancedNarrative=false&shapeFormat=raw&generalize=200&locale=fr_FR&unit=k&from="+latitude+","+longitude+"&to="+json[0].lat+","+json[0].lng+"&narrativeType=none", true);
xhr.send(null);

All the parameters in the URL are defined above in the code.

I just don't understand why does it work (because it shouldn't as these requests are cross-domains) and why it works for nominatim and not for directions !

Thanks

Musa
  • 96,336
  • 17
  • 118
  • 137

1 Answers1

0

Nominatim supports CORS (which allows browsers to do cross-domain requests to the Nomatim API). Mapquest doesn't, as alluded to by this comment on the mapquest forums.

broofa
  • 37,461
  • 11
  • 73
  • 73