Jquery getScript 与 json 调用的问题
您好,最近我让这段代码正常工作。加载 Jquery 后,我这样做:
function twitterCallback2(twitters) {
var statusHTML = [];
for (var i=0; i<twitters.length; i++){
var username = twitters[i].user.screen_name;
var status = twitters[i].text.replace(/((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!])/g, function(url) {
return '<a href="'+url+'">'+url+'</a>';
}).replace(/\B@([_a-z0-9]+)/ig, function(reply) {
return reply.charAt(0)+'<a href="http://twitter.com/'+reply.substring(1)+'">'+reply.substring(1)+'</a>';
});
statusHTML.push('<li><span>'+status+'</span> <a style="font-size:85%" href="http://twitter.com/'+username+'/statuses/'+twitters[i].id_str+'">'+relative_time(twitters[i].created_at)+'</a></li>');
}
if(document.getElementById('twitter_update_list').length>0)
document.getElementById('twitter_update_list').innerHTML = statusHTML.join('');
}
function relative_time(time_value) {
var values = time_value.split(" ");
time_value = values[1] + " " + values[2] + ", " + values[5] + " " + values[3];
var parsed_date = Date.parse(time_value);
var relative_to = (arguments.length > 1) ? arguments[1] : new Date();
var delta = parseInt((relative_to.getTime() - parsed_date) / 1000);
delta = delta + (relative_to.getTimezoneOffset() * 60);
if (delta < 60) {
return 'Hace menos de un minuto';
} else if(delta < 120) {
return 'hace un minuto';
} else if(delta < (60*60)) {
return "Hace "+(parseInt(delta / 60)).toString() + ' minutos';
} else if(delta < (120*60)) {
return 'Hace una hora';
} else if(delta < (24*60*60)) {
return 'Hace ' + (parseInt(delta / 3600)).toString() + ' horas';
} else if(delta < (48*60*60)) {
return 'Hace un día';
} else {
return "Hace "+ (parseInt(delta / 86400)).toString() + ' días';
}
}
$.getScript("https://twitter.com/statuses/user_timeline/buscocarro.json?callback=twitterCallback2&count=10", function(){});
直到几天前,它停止工作,并且 Google Chrome 控制台 说:
资源解释为脚本,但使用 MIME 类型 application/json 进行传输。
你们中的任何人都可以告诉我发生了什么事以及如何解决? 多谢
Greetings, recently I had this code working. After loading Jquery I do:
function twitterCallback2(twitters) {
var statusHTML = [];
for (var i=0; i<twitters.length; i++){
var username = twitters[i].user.screen_name;
var status = twitters[i].text.replace(/((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!])/g, function(url) {
return '<a href="'+url+'">'+url+'</a>';
}).replace(/\B@([_a-z0-9]+)/ig, function(reply) {
return reply.charAt(0)+'<a href="http://twitter.com/'+reply.substring(1)+'">'+reply.substring(1)+'</a>';
});
statusHTML.push('<li><span>'+status+'</span> <a style="font-size:85%" href="http://twitter.com/'+username+'/statuses/'+twitters[i].id_str+'">'+relative_time(twitters[i].created_at)+'</a></li>');
}
if(document.getElementById('twitter_update_list').length>0)
document.getElementById('twitter_update_list').innerHTML = statusHTML.join('');
}
function relative_time(time_value) {
var values = time_value.split(" ");
time_value = values[1] + " " + values[2] + ", " + values[5] + " " + values[3];
var parsed_date = Date.parse(time_value);
var relative_to = (arguments.length > 1) ? arguments[1] : new Date();
var delta = parseInt((relative_to.getTime() - parsed_date) / 1000);
delta = delta + (relative_to.getTimezoneOffset() * 60);
if (delta < 60) {
return 'Hace menos de un minuto';
} else if(delta < 120) {
return 'hace un minuto';
} else if(delta < (60*60)) {
return "Hace "+(parseInt(delta / 60)).toString() + ' minutos';
} else if(delta < (120*60)) {
return 'Hace una hora';
} else if(delta < (24*60*60)) {
return 'Hace ' + (parseInt(delta / 3600)).toString() + ' horas';
} else if(delta < (48*60*60)) {
return 'Hace un día';
} else {
return "Hace "+ (parseInt(delta / 86400)).toString() + ' días';
}
}
$.getScript("https://twitter.com/statuses/user_timeline/buscocarro.json?callback=twitterCallback2&count=10", function(){});
Until some days ago it stopped working and the Google Chrome console says:
Resource interpreted as script but transferred with MIME type application/json.
Any of you could tell me what happened and how it can be solved?
thanks a lot
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试使用标准 AJAX 调用。
这会做同样的事情,但不会将文件作为脚本加载。
You could try using a standard AJAX call.
That would do the same thing, but wouldn't load the file as a script.