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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With