Вот мой код, основанный на этом вопросе
Код: Выделить всё
$(document).ready(function(){
$('#new-quote').click(function(){
var url = 'http://api.forismatic.com/api/1.0/?format=jsonp&jsonp=_';
$.getJSON(url, function(data){
console.log(data);
});
});
});
XMLHttpRequest cannot load http://api.forismatic.com/api/1.0/?format=jsonp&jsonp=. Redirect from 'http://api.forismatic.com/api/1.0/?format=jsonp&jsonp=' to 'http://forismatic.com/' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access.
I've also tried the code:
Код: Выделить всё
$(document).ready(function(){
$('#new-quote').click(function(){
var url = 'http://api.forismatic.com/api/1.0/?format=jsonp&jsonp=_';
$.getJSON(url).done(update).fail(err);
function update(response){
console.log(response);
}
function err(jqxhr, textStatus, err){
console.log('Request failed');
}
});
});
This question asks about the underlying concept of Access-Control-Allow-Origin. The guy also literally states that he doesn't want to use jsonp. I want use jsonp format with $.getJSON format and am not sure why it's not working.
Источник: https://stackoverflow.com/questions/412 ... cors-error
Мобильная версия