1

我有一个在我的谷歌地图上运行的应用程序。但是今天开始给出错误:

XMLHttpRequest can not load http://maps.googleapis.com/maps/api/elevation/json?locations=-26.905, -49.05694 & sensor = true. Http://localhost:36452 Origin is not allowed by Access-Control-Allow-Origin.

JQuery 的调用是这样的:

function alturaPonto(lat, lng, edt)
{
  $.ajax({
    type: "GET",            
    dataType: 'json',
    crossDomain: true,
    url: "http://maps.googleapis.com/maps/api/elevation/json?locations=" + lat + "," + lng + "&sensor=true",
    success: function (msg) {                    
        var retorno = msg.results[0].elevation;                    
        edt.val(retorno);
    }
  });                
}

一切正常,但现在出现错误。下面的结果有效,并由按钮调用。之后,或者如果我在地图上单击以在地图上创建一个点并乘坐电梯不起作用。如果调用相同,为什么两个返回之间的差异?

Request URL:http://maps.googleapis.com/maps/api/elevation/json?locations=-26.905,-49.05694&sensor=false
Request Method:GET
Status Code:200 OK (from cache)
Query String Parametersview sourceview URL encoded
locations:-26.905,-49.05694
sensor:false

不工作

Request URL:http://maps.googleapis.com/maps/api/elevation/json?locations=-26.899415168090034,-49.05200242996216&sensor=false
Request Headersview parsed
GET http://maps.googleapis.com/maps/api/elevation/json?locations=-26.899415168090034,-49.05200242996216&sensor=false HTTP/1.1
Accept: application/json, text/javascript, */*; q=0.01
Referer: http://localhost:36452/Posicionador
Origin: http://localhost:36452
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36
Query String Parametersview sourceview URL encoded
locations:-26.899415168090034,-49.05200242996216
sensor:false

如何直接在 JQuery 中解决这个问题?tks

4

0 回答 0