我试图找出为什么 JSON 不能在整个论坛和互联网上的 Firefox 中工作。它适用于平板电脑,即 safari。它可以在我的 Firefox 桌面上运行,但在它上线后就不行了。我尝试了一些东西(注释掉),例如没有解决方案的 mimeType。我曾尝试使用 $.ajax,但运气不佳。Firefox 没有 javascript 错误。我正在使用 jQuery 1.7。
Console.log 正在打印数据。div introCon 是空的(仅在 Firefox 上)。
$(document).ready(function() {
jQuery.support.cors = true;
//$.ajaxSetup({ mimeType: "application/json" });
/*$.ajaxSetup({ scriptCharset: "utf-8" , contentType: "application/json; charset=utf-8"}); */
// loading pictures
$.getJSON("intro.json?format=json", function(data){
var links = '';
var imageload = '';
var title = '';
console.log(data);
$.each(data, function(key, item) {
links += ' <a href=' + item.image + '>' + key + '</a>';
imageload += '<img src="' + item.image + ' " />';
title += item.alt;
});
$('.introCon').html(imageload);
$('.introCon img').hide();
$('.introCon img:last').fadeIn(500);
$('.introCon img').fadeIn(1000);
rotatePics(2);
});
});
function rotatePics(currentPhoto) {
var numberOfPhotos = $('.introCon img').length;
currentPhoto = currentPhoto % numberOfPhotos;
$('.introCon img').eq(currentPhoto).fadeOut( function() {
// re-order the z-index
$('.introCon img').each(function(i) {
$(this).css(
'zIndex', ((numberOfPhotos - i) + currentPhoto) % numberOfPhotos
);
});
$(this).show();
setTimeout(function() {rotatePics(++currentPhoto);}, 3000);
});
}
这是来自单独文件的简单 JSON。
{
"1" : {
"image" : "portfolio/chrpic.png",
"alt" : "Blah.",
"detail": "Quartz"},
"2" : {
"image" : "portfolio/mysspic.png",
"alt" : "Landing page.",
"detail": "Container"},
"3" : {
"image" : "portfolio/decode-pic3.png",
"alt" : "Decode this.",
"detail": "Landing page 2"},
"4" : {
"image" : "portfolio/simple-think-pic.png",
"alt" : "Simple Think",
"detail": "simpilify your life"}
}