none
either crossdomain error or token error, I cannot get data from REST API, Please HELP RRS feed

  • Question

  • I am using location API, to Get the latitude and longitude coordinates based on a set of address values

    If I use simple json I get the "No 'Access-Control-Allow-Origin'" error. If I use jsonp I get "Unexpected token :" error

    $.ajax({
    	url: encodeURI ('http://dev.virtualearth.net/REST/v1/Locations?countryRegion=UK&locality=manchester&postalCode=m16+9af&key=key'),
          type: "GET",
          dataType: 'jsonp',
    	  jsonp: "callback",
    	  success: function(r) {
    	var lat=r.resourceSets[0].resources[0].point.coordinates[0],
    	lng=r.resourceSets[0].resources[0].point.coordinates[1];
            console.log(r);
          },
          error: function(response) {
            console.log(JSON.stringify(response));
          }
        });
    

    The above throws Uncaught SyntaxError: Unexpected token :

    If I change datatype to json, I get "XMLHttpRequest cannot load http…=json&key=... No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.

    What should I do to get the result?

    Wednesday, June 21, 2017 3:27 PM

Answers

  • I believe the jsonp parameter needs to be set to jsonp and not callback. Here is a sample https://github.com/Microsoft/BingMapsV8CodeSamples/blob/master/Samples/Rest%20Services/RestServices_jQuery.html

    [Blog] [twitter] [LinkedIn]

    • Proposed as answer by Ricky_Brundritt Thursday, June 22, 2017 4:08 AM
    • Marked as answer by JrDai Sunday, June 25, 2017 1:57 PM
    Thursday, June 22, 2017 4:08 AM