调用stackoverflow api时出错

时间:2016-12-02 14:48:00

标签: javascript angularjs

我正在尝试使用stackoverflow的api在stackoverflow中使用标记ipv4获取所有问题。但我有以下错误No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access.

我在堆栈交换中注册了我的应用程序。但我不知道如何认证它。

您能提供帮助吗,非常欢迎教程或文档

这是我目前的代码:

$http.get( "http://api.stackexchange.com/docs/questions#order=desc&sort=activity&tagged=ipv4&filter=!BHMIbze0EPheMk572h0ktETsgnphhU&site=stackoverflow&run=true")
            .success(function(data) {
                console.log(data);
            });

1 个答案:

答案 0 :(得分:1)

发出请求的网址不正确您已正确连接到网址?

这是一个例子

$.ajax({
    url:'https://api.stackexchange.com/2.2/questions?order=desc&sort=activity&tagged=ipv4&site=stackoverflow&filter=!BHMIbze0EPheMk572h0ktETsgnphhV',
    complete: function (response) {
        $('#output').html(response.responseText);
    },
    error: function () {
        $('#output').html('Bummer: there was an error!');
    },
});

http://jsfiddle.net/heanfig/v5hLzmud/1/