【问题标题】:Javascript/ajax/node.js/other framework CORS request using jsfiddle [duplicate]使用 jsfiddle 的 Javascript/ajax/node.js/其他框架 CORS 请求 [重复]
【发布时间】:2018-03-14 02:50:43
【问题描述】:

我正在尝试使用来自 fiddle 的 JQuery ajax 调用从 this page 加载资源

我的代码在这里:

$('button').on('click', function() {
    $('#message').text('');
    $.ajax({
        url: "http://pool.burstcoin.ro/pending2.json",
        type: "GET",
        crossDomain: true,
        dataType: "json",
        success: function(response) {
            console.log(response);
            $('#message').text(response.message);
        },
        error: function(xhr, status) {
            alert("error");
        }
    });
});

我创建了fiddle 只是为了看看我是否可以得到任何类型的响应,但我得到了这个 js 错误响应: 请求的资源上没有“Access-Control-Allow-Origin”标头。 我已经阅读了一些关于此的帖子,如果我没记错的话,不可能在前端做任何事情来添加缺失的标题。是否可以在 Node.js(或其他一些 JavaScript 框架)中将正确的标头添加到响应中? 如果是这样,我真的很感激一个更新的小提琴,因为我自己缺乏知识来证明这一点。

【问题讨论】:

标签: javascript jquery node.js ajax


【解决方案1】:

使用Yahoo's YQL解决

Fiddle

function GetMessages()
{

$.getJSON("http://query.yahooapis.com/v1/public/yql",
  {
    q:      "select * from json where url=\"http://pool.burstcoin.ro/pending2.json\"",
    format: "json"
  },
  function (data) {
    if (data.query.results) {
        alert(data.query.results["pendingPaymentList"]["_00079785104091711"]);
    } else {
      alert('bad');
    }
  }
);
}

GetMessages();

【讨论】:

    猜你喜欢
    • 2015-03-01
    • 2016-11-01
    • 2023-03-21
    • 2011-08-19
    • 2018-06-16
    • 2017-05-05
    • 2017-04-14
    • 2015-03-02
    • 2020-06-13
    相关资源
    最近更新 更多