Может кто-нибудь сказать мне, как изменить этот getJSON
запрос на .ajax
вызов, чтобы я мог установить параметр contentType
?
$.getJSON('json/showreel.json', function(data) {
//get total number of JSON objects and generate random numder
var total = data.length;
var randnum = Math.floor(Math.random()*total)
//Loop through each of the JSON objects to check if matches random number
$.each(data, function(entryIndex, entry) {
if(entryIndex === randnum){
var info = '<div class="entry" style="color:' + entry['colour'] + '">';
info += entry['title'] + '<br />';
info += '<a href="' + entry['link_url'] + '">' + entry['website'] + '</a>';
info += '</div>';
$('#head-contact,#head-contact a').css('color',entry['colour']);
//create new image object to preload image
var img = new Image();
//once image has loaded execute this code
$(img).load(function () {
//$(this).css('display', 'none'); // .hide() doesn't work in Safari when the element isn't on the DOM already
$(this).hide();
$('#showreel').removeClass('loading').append(this);
$(this).fadeIn(3000);
}).error(function () {
// notify the user that the image could not be loaded
}).attr('src', entry['image_src']);
}
$('#info').append(info);
});
});
Большое спасибо,
C