perhaps? 2018-06-04 23:25 采纳率: 100%
浏览 64

获取jsfiddle JSON内容

The following simplified previously working code:

  $.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);
    }
  });

I receive the following error:

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.

I initially thought that the issue was json vs jsonp or http vs https. All attempts return the same result.

if you run from the addy bar the browser identifies the mime correctly & you get the json as expected:

[
{
"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"
}

]

The code worked as recently as yesterday. What can I do to fix it? Why is my page disputing the application/json mime?

  • 写回答

1条回答 默认 最新

  • weixin_33712881 2020-01-06 15:03
    关注

    Here is what worked and is working today (Jan 2020). Basically, here i have created an html table and I append the fiddle rows to the body.

    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);
    }
    
    评论

报告相同问题?