1

Fiddler がエラーを報告していない場合でも、次の jQuery ajax が常にエラー コールバックを呼び出すのはなぜですか。

 $.ajax({
        type: 'GET',
        url: "http://open.mapquestapi.com/nominatim/v1/search?format=json&viewbox=-122%2C46%2C-73%2C40&countrycodes=ca&bounded=1&addressdetails=0&q=[hotel]",
        dataType: 'jsonp',
        jsonp: 'json_callback',
        error: function(parameters) {
            alert(parameters);
        },
        success: searchCompleteCallBack
    });

これは Fiddler セッションです。成功していますが、以下に示すように、ステータス アイコンとして横に線が入った赤い円があります。 ここに画像の説明を入力

GET /nominatim/v1/search?format=json&viewbox=-122%2C46%2C-73%2C40&countrycodes=ca&bounded=1&addressdetails=0&q=[hotel]&json_callback=jQuery17108850838504386628_1334974646679&_=1334974661295 HTTP/1.1
Accept: application/javascript, */*;q=0.8
Referer: http://localhost:50383/?AspxAutoDetectCookieSupport=1
Accept-Language: en-US
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; BOIE9;ENGB)
Accept-Encoding: gzip, deflate
Host: open.mapquestapi.com
Connection: Keep-Alive


HTTP/1.1 200 OK
Date: Sat, 21 Apr 2012 02:17:41 GMT
Server: Apache
Content-Location: search.php
Vary: negotiate
TCN: choice
Access-Control-Allow-Origin: *
Content-Length: 4775
Keep-Alive: timeout=5, max=91
Connection: Keep-Alive
Content-Type: application/json; charset=UTF-8

jQuery17108850838504386628_1334974646679([{"place_id":"2166467243","licence":"Data Copyright OpenStreetMap Contributors, Some Rights Reserved. CC-BY-SA 2.0.","osm_type":"node","osm_id":"1417990074","boundingbox":["43.0738813782","43.0938851929","-79.0912683105","-79.0712606812"],"lat":"43.0838817","lon":"-79.0812662","display_name":"Quality Hotel, Murray Street, Niagara Falls, Ontario, Ontario, Canada","class":"tourism","type":"hotel","icon":"http://open.mapquestapi.com/nominatim/v1/images/mapicons/accommodation_hotel2.p.20.png"},{"place_id":"2085733959","licence":"Data Copyright OpenStreetMap Contributors, Some Rights Reserved. CC-BY-SA 2.0.","osm_type":"way","osm_id":"97928121","boundingbox":["49.8510055541992","49.8513870239258","-97.1532821655273","-97.1526718139648"],"lat":"49.8512060913871","lon":"-97.1530114466667","display_name":"Pembina Hotel, 1011, Pembina Highway, Point Road, Winnipeg, Manitoba, Canada","class":"amenity","type":"hotel"},{"place_id":"2152638544","licence":"Data Copyright OpenStreetMap Contributors, Some Rights Reserved. CC-BY-SA 2.0.","osm_type":"node","osm_id":"1324405899","boundingbox":["43.8393080139","43.8593118286","-79.3921792603","-79.3721716309"],"lat":"43.849309","lon":"-79.382178","display_name":"Holiday Inn Express & Suites, Fulton Way, Thornlea, Markham, Ontario","class":"tourism","type":"hotel","icon":"http://open.mapquestapi.com/nominatim/v1/images/mapicons/accommodation_hotel2.p.20.png"},{"place_id":"2177668535","licence":"Data Copyright OpenStreetMap Contributors, Some Rights Reserved. CC-BY-SA 2.0.","osm_type":"way","osm_id":"138157978","boundingbox":["43.4092330932617","43.4098968505859","-80.3297119140625","-80.3289260864258"],"lat":"43.40953956119","lon":"-80.3293440133707","display_name":"Hespeler Road, Cambridge, Ontario, Canada","class":"tourism","type":"hotel","icon":"http://open.mapquestapi.com/nominatim/v1/images/mapicons/accommodation_hotel2.p.20.png"},{"place_id":"2138545308","licence":"Data Copyright OpenStreetMap Contributors, Some Rights Reserved. CC-BY-SA 2.0.","osm_type":"node","osm_id":"1280026038","boundingbox":["43.6322805786","43.6522843933","-79.4218270874","-79.401819458"],"lat":"43.6422834","lon":"-79.4118234","display_name":"Palace Arms, Strachan Avenue, Liberty Village, Toronto, Ontario, M5A1Z9, Canada","class":"tourism","type":"hostel"},{"place_id":"5773486","licence":"Data Copyright OpenStreetMap Contributors, Some Rights Reserved. CC-BY-SA 2.0.","osm_type":"node","osm_id":"583902387","boundingbox":["45.3422987366","45.3623025513","-75.6427056885","-75.6226980591"],"lat":"45.3522996","lon":"-75.6327046","display_name":"Bank Street, Blossom Park, Ottawa, Ontario","class":"tourism","type":"hotel","icon":"http://open.mapquestapi.com/nominatim/v1/images/mapicons/accommodation_hotel2.p.20.png"},{"place_id":"2170250899","licence":"Data Copyright OpenStreetMap Contributors, Some Rights Reserved. CC-BY-SA 2.0.","osm_type":"node","osm_id":"1445914835","boundingbox":["43.1746237183","43.194627533","-79.5842340088","-79.5642263794"],"lat":"43.1846249","lon":"-79.5742298","display_name":"Beamer Falls Manor at Falconridge Farm, Ridge Road West, Grimsby, Ontario, Canada","class":"tourism","type":"hotel","icon":"http://open.mapquestapi.com/nominatim/v1/images/mapicons/accommodation_hotel2.p.20.png"},{"place_id":"2664364","licence":"Data Copyright OpenStreetMap Contributors, Some Rights Reserved. CC-BY-SA 2.0.","osm_type":"node","osm_id":"343055090","boundingbox":["43.6355078125","43.6555116272","-79.4053170776","-79.3853094482"],"lat":"43.6455088","lon":"-79.3953127","display_name":"Global Village Backpackers Hostel, King Street West, Fashion District, Toronto, Ontario, M5A1Z9, Canada","class":"tourism","type":"hostel"},{"place_id":"2168185190","licence":"Data Copyright OpenStreetMap Contributors, Some Rights Reserved. CC-BY-SA 2.0.","osm_type":"way","osm_id":"129431482","boundingbox":["45.3853416442871","45.3861045837402","-75.733268737793","-75.7327346801758"],"lat":"45.3857092561038","lon":"-75.7330025913023","display_name":"Best Western Macies Hotel, Carling Avenue, Rideauview, Ottawa, Ontario, Canada","class":"tourism","type":"hotel","icon":"http://open.mapquestapi.com/nominatim/v1/images/mapicons/accommodation_hotel2.p.20.png"},{"place_id":"2166467244","licence":"Data Copyright OpenStreetMap Contributors, Some Rights Reserved. CC-BY-SA 2.0.","osm_type":"node","osm_id":"1417990095","boundingbox":["43.0724356079","43.0924394226","-79.0928704834","-79.072862854"],"lat":"43.0824382","lon":"-79.0828672","display_name":"Hilton Niagara Falls, Fallsview Boulevard, Niagara Falls, Ontario, Ontario, Canada","class":"tourism","type":"hotel","icon":"http://open.mapquestapi.com/nominatim/v1/images/mapicons/accommodation_hotel2.p.20.png"}]) 

私は実際にこれを少し前に機能させましたが、今何が間違っているのかわかりません。

4

2 に答える 2

0

jQuery-1.7.2.js では、動的な jsonp リクエスト スクリプトがロードされてから (8123 行目あたり)、サーバーから応答が返されて 8016 行にインストールされたコールバックが呼び出されるまでの間は灰色の領域です。このコールバックは、ウィンドウ オブジェクトのグローバル スコープで定義されていても、特定の状況では存在しないように見えます。このウィンドウ オブジェクトの下の子要素のレイアウトは、ASP.NET カミソリ部分ビューに直接配置されたチェックボックスをクリックして ajax を呼び出すことと関係がありますが、OpenLayers.Popup.FrameCloud 内のボタンから呼び出すと、この問題。

回避策は、次のように、jQuery がランダム関数を jsonp コールバックとして定義しないようにすることです。

$.ajax({
        type: 'GET',
        url: "http://open.mapquestapi.com/nominatim/v1/search?format=json&viewbox=-122%2C46%2C-73%2C40&countrycodes=ca&bounded=1&addressdetails=0&q=[hotel]&json_callback=onSearchComplete",
        dataType: 'jsonp',
        jsonp: false,
        error: function(parameters) {
            alert(parameters);
        }
    });

この場合、「onSearchComplete」はスクリプトで定義されたグローバル関数です。このセットアップでは、ajax クエリがどのように呼び出されたかに関係なく、サーバーの応答が成功すると常に onSearchComplete が呼び出されます。この場合の問題は、json 要求の一部として送信されていないにもかかわらず、jQuery がランダムな名前のコールバック関数を作成してインストールすることです。その結果、ランダムに生成されたコールバックは実行されず、jQuery はこれをエラー状態として扱います。

おそらく、jQuery の達人はここでさらに光を当てることができます。

于 2012-05-01T17:40:45.607 に答える
0

Firefox でも Chrome でも問題を再現できません。

コンソールでこのコードを試して、何が起こったのかを確認してください。

$.ajax({
        type: 'GET',
        url: "http://open.mapquestapi.com/nominatim/v1/search?format=json&viewbox=-122%2C46%2C-73%2C40&countrycodes=ca&bounded=1&addressdetails=0&q=[hotel]",
        dataType: 'jsonp',
        jsonp: 'json_callback',
        error: function(parameters) {
            console.error("error");
            console.error(parameters);
        },
        success: function(parameters) {
            console.log("success");
            console.log(parameters);
        },
    });

そして、私はこれを得ました:

XMLHttpRequest
success
[
Object
, 
Object
, 
Object
, 
Object
, 
Object
, 
Object
, 
Object
, 
Object
, 
Object
, 
Object
]
于 2012-04-21T02:55:42.373 に答える