API JSON callback issue

I have a simple input field that brings back shows as you search for them, using the Trakt API. Recently they changed their API and now my code no longer works (it used to). I’m getting this issue:

Refused to execute script from http://.... because its MIME type ('application/json') is not executable, and strict MIME type checking is enabled.

CODE:

  $.ajax ({
    type: "GET",
    // **OBSOLETE** url: 'http://api.trakt.tv/search/shows.json/78c0761c9409a61cf88e675687d6f790/'+ value +'/5/seasons/',
    url: 'http://api.trakt.tv/search/shows.json/78c0761c9409a61cf88e675687d6f790?query=' + value + '&limit=5&seasons=true',
    dataType: "jsonp",
    json: "callbackname",
    crossDomain : true,

If I remove:

dataType: "jsonp",

or change to:

dataType: "json",

I get a different error:

XMLHttpRequest cannot load http://.... No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://dl.dropboxusercontent.com' is therefore not allowed access.

Demo: http://dl.dropboxusercontent.com/u/48552248/websites/tiii.me/index.html (‘load unsafe script’ if https:// is forced)

Link to code: https://dl.dropboxusercontent.com/u/48552248/websites/tiii.me/scripts/partials/_tv-show.js

Any ideas? Thanks!

Answers:

Answer

try this one

function getJSONP(url, success) {

    var ud = '_' + +new Date,
        script = document.createElement('script'),
        head = document.getElementsByTagName('head')[0] 
               || document.documentElement;

    window[ud] = function(data) {
        head.removeChild(script);
        success && success(data);
    };

    script.src = url.replace('callback=?', 'callback=' + ud);
    head.appendChild(script);

}
Answer

Looks like the response you are getting is not a jsonp response but a json response. In jsonp you should get a javascript method callback. Whereas in your case its plain json data. so you need to process the json data and manually call the callbackname method and pass the object that you are getting back as json result.

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.