"The resource is interpreted as a script, but is passed using a MIME-type application / json" using the Youtube JavaScript API

I get the message "Resource interpreted as a script, but transmitted with a MIME type message / json" using the Google Chrome JavaScript console.

The following code is currently running 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);

});

Can I find out what causes the error?

I tried using 'callback =?', 'Jsoncallback =?' for a callback, but everything results in the same error message.

Can I find out how to fix this?

Regards.

+5
source share
3 answers

JSONP, : IMHO:

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

callback, jQuery , .

+8

, , .

, YouTube .

+4

Chrome XHR .

, json , URL- .

var xhr_object = new XMLHttpRequest();

var url = 'mysite.com/party_in_my_pants'; // Using this one, Chrome throws error

var url = 'mysite.com/party_in_my_pants?'; // This one, Chrome is sexy.

xhr_object.open('POST', url, false);
0

All Articles