0

我正在做一个项目,我必须对 LSD Finder 进行 jQuery 调用。为了澄清,在这种情况下,LSD 不是药物:它是土地分区。加拿大被分成数百块甚至数千块土地,它们都有一个数字,例如:14-22-25-02-W5。没关系,这对您没有任何意义,有一个 API。

但由于某些愚蠢的原因,我无法让该 API 正常工作。我的 jQuery AJAX 查询很简单:

//the variable 'value' comes from an input, and is correct
var url = "https://www.lsdfinder.com/api/v1/SECRETKEY/lsd/"+value;

$.ajax({
    url: url,
dataType: 'json',
success: function(json) {
    alert('anything?');
},
    error: function(e) {
    alert('nothing');
}
});

我是否使用 dataType json 或 jsonp 似乎并不重要,我一直得到“无”。我尝试通过修改错误回调以读取以下内容来获得更智能的错误,例如响应文本或其他内容:

error: function(jqXHR, textStatus, errorThrown) {
alert(jqXHR.toSource());
alert(textStatus.toSource());
alert(errorThrown.toSource());
}

我的回答是,包括原来的错误函数:

nothing

//deep breath, and....
({readyState:0, setRequestHeader:(function (a,b){if(!v){var c=a.toLowerCase();a=u[c]=u[c]||a,t[a]=b}return this}), getAllResponseHeaders:(function (){return v===2?e:null}), getResponseHeader:(function (a){var c;if(v===2){if(!f){f={};while(c=cl.exec(e))f[c[1].toLowerCase()]=c[2]}c=f[a.toLowerCase()]}return c===b?null:c}), overrideMimeType:(function (a){return v||(l.mimeType=a),this}), abort:(function (a){return a=a||w,g&&g.abort(a),y(0,a),this}), state:(function (){return c}), always:(function (){return e.done(arguments).fail(arguments),this}), then:(function (){var a=arguments;return p.Deferred(function(c){p.each(b,function(b,d){var f=d[0],g=a[b];e[d[1]](p.isFunction(g)?function(){var a=g.apply(this,arguments);a&&p.isFunction(a.promise)?a.promise().done(c.resolve).fail(c.reject).progress(c.notify):c[f+"With"](this===e?c:this,[a])}:c[f])}),a=null}).promise()}), promise:(function (a){return typeof a=="object"?p.extend(a,d):d}), pipe:(function (){var a=arguments;return p.Deferred(function(c){p.each(b,function(b,d){var f=d[0],g=a[b];e[d[1]](p.isFunction(g)?function(){var a=g.apply(this,arguments);a&&p.isFunction(a.promise)?a.promise().done(c.resolve).fail(c.reject).progress(c.notify):c[f+"With"](this===e?c:this,[a])}:c[f])}),a=null}).promise()}), done:(function (){if(i){var b=i.length;(function d(b){p.each(b,function(b,c){p.isFunction(c)&&(!a.unique||!l.has(c))?i.push(c):c&&c.length&&d(c)})})(arguments),e?g=i.length:c&&(f=b,k(c))}return this}), fail:(function (){if(i){var b=i.length;(function d(b){p.each(b,function(b,c){p.isFunction(c)&&(!a.unique||!l.has(c))?i.push(c):c&&c.length&&d(c)})})(arguments),e?g=i.length:c&&(f=b,k(c))}return this}), progress:(function (){if(i){var b=i.length;(function d(b){p.each(b,function(b,c){p.isFunction(c)&&(!a.unique||!l.has(c))?i.push(c):c&&c.length&&d(c)})})(arguments),e?g=i.length:c&&(f=b,k(c))}return this}), success:(function (){if(i){var b=i.length;(function d(b){p.each(b,function(b,c){p.isFunction(c)&&(!a.unique||!l.has(c))?i.push(c):c&&c.length&&d(c)})})(arguments),e?g=i.length:c&&(f=b,k(c))}return this}), error:(function (){if(i){var b=i.length;(function d(b){p.each(b,function(b,c){p.isFunction(c)&&(!a.unique||!l.has(c))?i.push(c):c&&c.length&&d(c)})})(arguments),e?g=i.length:c&&(f=b,k(c))}return this}), complete:(function (){if(i){var b=i.length;(function d(b){p.each(b,function(b,c){p.isFunction(c)&&(!a.unique||!l.has(c))?i.push(c):c&&c.length&&d(c)})})(arguments),e?g=i.length:c&&(f=b,k(c))}return this}), statusCode:(function (a){if(a){var b;if(v<2)for(b in a)r[b]=[r[b],a[b]];else b=a[x.status],x.always(b)}return this}), responseText:"", status:0, statusText:"error"})

new String("error")

new String("")

所以,正如你所看到的,它 100% 失败了,我不知道为什么。我想也许我返回的 JSON 数组不正确或损坏,所以我得到它并通过 JSONLint 运行它,它说它是有效的。只是为了让你看到它,它是:

[
{
    "query": "14-22-25-02-W5",
    "response": {
        "status": "ok",
        "err": [],
        "lat": 51.152259,
        "lng": -114.202199,
        "country": "Canada",
        "province": "AB",
        "city": "Calgary",
        "street": "49 Royal Vista Drive NW",
        "street_prox": 78,
        "address": "49 Royal Vista Drive NW, Calgary, AB",
        "lsd": "14-22-25-2 W5",
        "lsd_border": [
            [
                51.150459,
                -114.199327
            ],
            [
                51.150447,
                -114.205067
            ],
            [
                51.154059,
                -114.205071
            ],
            [
                51.154072,
                -114.199332
            ],
            [
                51.150459,
                -114.199327
            ]
        ],
        "uwi": "",
        "nts": "",
        "nts_border": [],
        "utm": "11S 695661E 15670479N",
        "utm_v": "Zone 11, 695661 meters easting, 15670479 meters northing (Southern Hemisphere)"
    }
}
]

最终,我想要做的是让这个查询工作,然后得到纬度和经度,并用它在动态谷歌地图上指出一个点。但首先,我需要让查询与我一起工作。我认为问题可能在于我正在 ajaxing 到一个 https 地址,但现在是凌晨 3:30,我无法直接思考,所以我希望有人有一个想法。

谢谢你。

4

2 回答 2

2

jQuery Ajax 默认不支持跨域查询。尝试添加crossDomain: true到您的请求选项。

于 2013-10-29T09:37:20.580 回答
0

您似乎正在访问不在您的服务器上的东西。

您需要使用粗调。

于 2013-10-29T09:35:43.517 回答