2017-10-19 125 views
0

我是API的新手,他们似乎一直在阻止我。我不断收到以下错误:使用API​​时出错Error

'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 
    }); 
    }); 
+0

我只是想在一个restles客户您的网址,我得到的错误: “对不起,你不能在这个网站上发帖。”看起来像http://quotesondesign.com/wp-json/posts的POST请求实际上是试图创建一个帖子。请咨询他们的API –

回答

1

正如@提到moataz-elmasry JS的功能是好的,但API访问限制。 运行相同的代码的小提琴运行良好: https://jsfiddle.net/9gtbsp2e/1/

*我更新的链接使用https删除安全错误

相关问题