获取jsfiddle json内容

时间:2018-06-04 23:25:23

标签: javascript jquery json ajax

以下简化的以前工作代码:

  $.ajax({
    type: 'GET',
    //dataType: 'json',
    dataType: 'jsonp',
    data: {},
    url: "https://jsfiddle.net/api/user/afabbro/demo/list.json",
    error: function (jqXHR, textStatus, errorThrown) {
        console.log(jqXHR)
    },
    success: function (msg) {
        console.log(msg);
    }
  });

我收到以下错误:

Refused to execute script from 'https://jsfiddle.net/api/user/afabbro/demo/list.json?
callback=jQuery332 ...SNIPd... &_=1553587384' because its MIME type ('application/json') 
is not executable, and strict MIME type checking is enabled.

我最初认为问题是json vs jsonp或http vs https。所有尝试都返回相同的结果。

如果您从addy栏运行,浏览器会正确识别mime&你按照预期得到了json:

[
{
"framework": "No-Library",
"version": 8,
"description": "",
"title": "Hello World Example",
"url": "//jsfiddle.net/afabbro/vrVAP/",
"author": "afabbro",
"latest_version": 12520,
"created": "2013-08-08 15:03:20"
}

该代码最近在昨天工作。我该怎么办才能修复它?为什么我的页面会对应用程序/ json mime提出异议?

1 个答案:

答案 0 :(得分:0)

今天(2020年1月)在这里起作用并且正在起作用。基本上,这里我创建了一个html表,并将小提琴行附加到正文中。

var url = 'http://jsfiddle.net/api/user/[DESIRED USER NAME]/demo/list.json?callback=?&start=' + start + '&limit=' + limit; //&sort=created

$.getJSON(url, function (data) {
    var box = $('#myFiddlesBody');
    var list = data.list;
    var title, description, created, framework, url, version;

    var item;
    var output = "";

    for (i = 0; i < list.length; i++) {
        item = list[i];
        created = item.created;
        description = item.description;
        framework = item.framework;
        version = item.latest_version;
        title = item.title;
        url = item.url;

        var fmtdDate = new Date(created.substring(0, 10)).customFormat("#MM#/#DD#/#YYYY#");

        output += "<tr class='entry'>";
        output += "<td><a target='_blank' href='" + url + version + "/'><span class='link'>" + title + "</span></a></td>";
        output += "<td>" + version + "</td>";
        output += "<td>" + fmtdDate + "</td>";
        output += "<td>" + framework + "</td>";
        output += "<td>" + description + "</td>";
        output += "</tr>";
    }

    box.append(output);
}