Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery getJSON/ajax gives no response from REST service

I am trying to use the Bing Maps REST service to get information about a city's location using a city's name. While the query string returns a response when I enter it directly in the browser, I can't seem to do in within my jquery code. I have the following:

var cs = "san diego";
var qs = "http://dev.virtualearth.net/REST/v1/Locations?q=" + cs + "&type=xml&key=MY_BING_MAPS_KEY";
jQuery.getJSON(qs, function(hs){alert(hs)});

According to firebug I am simply getting nothing in response (response code is 200). Any idea what could be going on? I have other REST calls in other parts of my code and there is absolutely no issue there.

The documentation for using the API is here: http://msdn.microsoft.com/en-us/library/ff701711.aspx

Thanks!

**EDIT: Actually there is a way to overcome this by forcing JSONP from bing maps by doing the following:

$.ajax({
            url: "http://dev.virtualearth.net/REST/v1/Locations",
        dataType: "jsonp",
        data: {
            key: key,
            q: q
        },
        jsonp: "jsonp",
        success: function (data) {

        }
    });

**

like image 480
Haoqi Avatar asked Nov 20 '25 09:11

Haoqi


1 Answers

You are trying to make a cross domain ajax call, meaning you are making an ajax call to a domain different than the one running your app! You need to read how to do that. Here is a link

like image 137
gred Avatar answered Nov 22 '25 23:11

gred