Я новичок в API, и они, похоже, меня подвешивают. Я продолжаю получать следующую ошибку:
Заголовок заголовка "Access-Control-Allow-Origin" имеет значение " http://null ", не равное исходному началу. Поэтому исходный 'null' не допускается.
Вот мой JS:
var url = "http://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1";
$('#quotebutton').on('click', function(e) {
e.preventDefault();
$.ajax( {
url: "http://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1",
success: function(data) {
var post = data.shift(); // The data is an array of posts. Grab the first one.
$('#quote-title').text(post.title);
$('#quote').html(post.content);
// If the Source is available, use it. Otherwise hide it.
if (typeof post.custom_meta !== 'undefined' && typeof post.custom_meta.Source !== 'undefined') {
$('#quote-source').html('Source:' + post.custom_meta.Source);
} else {
$('#quote-source').text('');
}
},
cache: false
});
});
Как упоминалось в @moataz-elmasry, функция js прекрасна, но API имеет ограничения доступа. Запуск скрипта того же кода выполняется просто отлично: https://jsfiddle.net/9gtbsp2e/1/
* Я обновил ссылку, чтобы использовать https
для устранения ошибок безопасности