編集:私は解決策を自分で考え出しましたが、なぜこれがうまくいったのか答えてみたいです。私はURLからhttps://を削除し、問題を修正しました。なぜこれが問題になるのか分かりません。たぶんhttpsがより安全ですか?JSはForismatic APIからデータを引き出していません
私の関連するHTMLとJsコードのいくつかは、codepenで書かれているので、ヘッダーとライブラリはコードに直接記述されていません。コードページへのリンクは次のとおりです。https://codepen.io/slicknick/pen/vXVYpg
これは、Forismatic APIを使用してランダムなクォートジェネレータを作成するプロジェクトです。私はAPIとJsに新しいです。私は私のページに表示するために引用符を得ることができないようで、なぜこれが起こっているのかについてのいくつかのフィードバックをしたいと思います。
HTML
<div class="container-fluid">
<div class="row">
<div class="col-xs-6 col-centered">
<blockquote>
<p id="quote-text"></p>
<footer>
<a id="author" target="_blank"></a>
</footer>
</blockqoute>
<button type="button" id="getQuote" class="btn btn-secondary">New quote</button>
<a href="http://twitter.com/home?status=%23Quote" target="_blank"><i class="fa fa-twitter-square fa-3x" id="twitter-share" aria-hidden="true"></i></a>
</div>
</div>
$(function() {
var author = $('#author');
var text = $('#quote-text');
getQuote(author, text);
$('#getQuote').click(function(event) {
event.preventDefault();
getQuote(author, text);
$('#twitter-share').removeClass("disabled");
$('#twitter-share').html("Share with Twitter!");
})
});
var tweetText = "";
$('#twitter-share').click(function() {
if (tweetText.length > 140) {
tweetText = "";
$(this).addClass("disabled");
$(this).html("140 chars exceeded!");
} else {
$(this).attr("href", "https://twitter.com/intent/tweet?text=" + tweetText);
}
})
function getQuote(author, text) {
var forismaticURL = "http://api.forismatic.com/api/1.0/? method=getQuote&lang=en&format=jsonp&jsonp=?"
$.getJSON(forismaticURL, function(data) {
text.html(data.quoteText);
if (data.quoteAuthor) {
author.html(data.quoteAuthor);
author.attr("href", data.quoteLink);
} else {
author.removeAttr("href");
author.html("<strong>Anonymous</strong>");
}
tweetText = data.quoteText + "By -" + data.quoteAuthor;
});
}
ありがとうございます。私はAPIに入るほど深いことをよりよく理解することができると確信しています。 –