编辑:我自己想出了解决方案,但我想知道为什么这是可行的。我从url中删除了https://,它解决了这个问题。不确定为什么这会成为一个问题。也许https更安全?
这是我的一些相关的HTML和Js代码,它是用codepen编写的,所以头文件和库不直接在代码中。下面是代码页面的链接:https://codepen.io/slicknick/pen/vXVYpg
这是一个使用格式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;
});
}发布于 2016-10-20 04:08:03
引用Forismatic文档
API方法调用以对URL .的HTTP请求的形式实现。
这就是为什么你在HTTPS上得到错误404的原因。
希望能有所帮助。
https://stackoverflow.com/questions/40139815
复制相似问题