"Resource interpreted as script but transferred with MIME type application/json" using Youtube's JavaScript API

27,691

Solution 1

Since you use JSONP, you should code it like this IMHO :

$.ajax(URL, {
    crossDomain:true, 
    dataType: "jsonp", 
    success:function(data,text,xhqr){
        $.each(data, function(i, item) {
            alert(item);
        });
    }
});

The correct parameter is callback but jQuery generates one automagically so dont specify it.

Solution 2

That's a warning, not an error, and shouldn't stop your code from working.

The fault is with YouTube for serving the data with the wrong content-type.

Share:
27,691
DjangoRocks
Author by

DjangoRocks

Updated on October 01, 2020

Comments

  • DjangoRocks
    DjangoRocks over 3 years

    I'm receiving a "Resource interpreted as script but transferred with MIME type application/json" error message using Google Chrome's JavaScript console.

    I'm currently running the following code on my local computer:

    var URL = "";
    var YOUTUBE_ROOT = "http://gdata.youtube.com/feeds/api/videos?alt=jsonc&v=2";
    var start_index = "&start-index=1";
    var callback = "&jsonp=?"
    function searchYouTube()
    {
      var q = encodeURIComponent(jQuery("#query").val());
      var query = "&q="+q;
      URL = YOUTUBE_ROOT+start_index+query+callback; 
      alert(URL);
        $.getJSON(URL, function(data) {
            $.each(data.items, function(i, item) {
                alert(item);
            });
        });
    
    
    }
    
    
    jQuery(document).ready(function () {
         jQuery("#searchYouTube").click(searchYouTube);
    
    });
    

    May I know what is causing the error?

    I've tried using 'callback=?' , 'jsoncallback=?' for the callback, but all leads to the same error message.

    May I know how do i fix this?

    Best Regards.

  • DjangoRocks
    DjangoRocks about 13 years
    wow thanks! seems like i still have a lot to learn with regards to JavaScript and JQuery. the data is showing up now.
  • jujule
    jujule about 13 years
    JSONP is used when you need to access cross domain data. Basically it's just a trick : a javascript scriptag is inserted in your page and the response have a javascript callback embedded.
  • kasimir
    kasimir about 12 years
    This does not solve the error mentioned ('Resource interpreted'... etc.), at least not for me, and when still serving with application/json. It only goes away when serving as text/javascript, which doesn't have any noticeable side effects.
  • Ben
    Ben over 11 years
    It does not alert anything on my side