0

LSD Finder への jQuery 呼び出しを行う必要があるプロジェクトに取り組んでいます。明確にするために、この場合、LSD はドラッグではありません。それは Land Sub Divisions です。カナダは数千とは言わないまでも数百の土地に分割されており、それらすべてに番号が付けられています。たとえば、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)"
    }
}
]

私が最終的にやりたいことは、このクエリを機能させ、緯度と経度を取得し、動的な Google マップ上でポイントを作成することです。しかし、まず、クエリを操作する必要があります。問題は、私が https アドレスに ajax しているという事実にあるのではないかと思いますが、今は午前 3 時 30 分で、はっきりとは考えられません。

ありがとうございました。

4

2 に答える 2

2

jQuery Ajax は、既定ではクロスドメイン クエリをサポートしていません。crossDomain: trueリクエスト オプションに追加してみてください。

于 2013-10-29T09:37:20.580 に答える
0

サーバー上にないものにアクセスしているようです。

COARSEを使用する必要があります。

于 2013-10-29T09:35:43.517 に答える