首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >JS没有从Forismatic拉取数据

JS没有从Forismatic拉取数据
EN

Stack Overflow用户
提问于 2016-10-20 03:18:47
回答 1查看 250关注 0票数 0

编辑:我自己想出了解决方案,但我想知道为什么这是可行的。我从url中删除了https://,它解决了这个问题。不确定为什么这会成为一个问题。也许https更安全?

这是我的一些相关的HTML和Js代码,它是用codepen编写的,所以头文件和库不直接在代码中。下面是代码页面的链接:https://codepen.io/slicknick/pen/vXVYpg

这是一个使用格式API创建随机引用生成器的项目。我是API和Js的新手。我似乎无法让引文显示在我的页面上,我想要一些关于为什么会发生这种情况的反馈。

HTML

代码语言:javascript
复制
<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>

代码语言:javascript
复制
$(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;
});
}
EN

回答 1

Stack Overflow用户

发布于 2016-10-20 04:08:03

引用Forismatic文档

API方法调用以对URL .的HTTP请求的形式实现。

这就是为什么你在HTTPS上得到错误404的原因。

希望能有所帮助。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40139815

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档