我發送GET請求(它返回JSON)。代碼看起來像:GET ajax請求
$.ajax({
url: "http://www.new.marketprice.ru/retrieveRegions.html",
dataType: "jsonp",
data: {
searchStr: request.term
},
error: function() {
console.log('epic fail');
},
success: function(data) {
console.log(data);
}
});
它返回(到控制檯);
Resource interpreted as Other but transferred with MIME type undefined.
epic fail
但Network
標籤我看到返回的數據GET請求:
[
{ "region":"Московская область","countryId":1,
"cityId":23,"regionId":12345,"city":"Москва","country":"Россия"},
{"region":"Ленинградская область","countryId":1,"cityId":453,
"regionId":54321,"city":"Санкт Петербург","country":"Россия"}
]
爲什麼error
回調叫什麼名字?
UPD
好吧,我設置json
現在沒有警告,但錯誤:
XMLHttpRequest cannot load http://www.new.marketprice.ru/retrieveRegions.html?searchStr=test. Origin http://new.marketprice.ru is not allowed by Access-Control-Allow-Origin
它是如此奇怪,因爲運行腳本位於同一個域中:(
是在該請求頁面不同域的網址試試? (json vs jsonp dataType。) – BNL
如果它位於同一個域中,請用'「/retrieveRegions.html」' – Blazemonger
@ mblase75替換'「http://www.new.marketprice.ru/retrieveRegions.html」'非常感謝!它現在有效。 – Ockonal