gpt4 book ai didi

javascript - 无法使用 jquery 从 API 获取值

转载 作者:行者123 更新时间:2023-12-01 02:33:33 25 4
gpt4 key购买 nike

我无法从 Random quote API 获取值。我不知道这个问题发生在哪里。是在取内容的时候还是返回到前端的时候。如果我有权访问日志,就可以弄清楚这一点。而且,我在互联网上免费找到了这个 API。我还是不明白回调参数的作用。请引用下面的屏幕截图

Random Quote API jquery

这是我的 html 代码

$(document).ready(function() {
$("#click").on("click", function() {
$.getJSON("http://quotesondesign.com/wp-json/posts?filter[orderBy]=rand&filter[posts_per_page]=1&callback=", function(key) {
$("#quote").append(key[0].content + "<br><p> - " + key[0].title + "</p>");
});
});
});
.position-message {
margin-left: 25%;
margin-right: 25%;
margin-top: 10%;
margin-bottom: 20%;
}

.background {
background-color: maroon;
}

.button-shape {
border-radius: 50%;
width: 50px;
height: 50px;
margin: auto;
}

.fa-size {}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Open+Sans:300,400,600,700&amp;lang=en" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<div class="container-fluid">
<div id="quote" class="well position-message"></div>
<br>
<br>
<div class="row text-center">
<button type="button" id="click" class="button-shape"><i class="fa fa-refresh fa-2x"></i></button>
</div>
</div>

下面是我的网页的快照。我正在尝试在白色区域 <div id="quote" class="well position-well"> 打印随机引用每当单击按钮时。

Random Quote webpage

最佳答案

Seems that there is something wrong with your server's "Access-Control-Allow-Origin".

抱歉造成误导,http://null 似乎是由 stackoverflow 的 Run code snippet 引起的。

I made a working copy (no code change besides change the `http` to `https`):

https://jsfiddle.net/qex5y16v/1/

关于javascript - 无法使用 jquery 从 API 获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48129916/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com