Метод jQuery $.getJSON все еще выдает ошибку CORSJquery

Программирование на jquery
Ответить
Гость
 Метод jQuery $.getJSON все еще выдает ошибку CORS

Сообщение Гость »


Вот мой код, основанный на этом вопросе

Код: Выделить всё

$(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);
});
});
});
This get's me the error:


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');
}
});
});
And it gives me the same error. Along with the 'Request failed message'. I'm using jQuery 3.1.1. What am I missing here? Sorry if this is a duplicate but I've read the questions here and haven't found the answer

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
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Jquery»