我有以下自定义插件代码
(function ($) {
$.fn.createGallery = function(options) {
var theObject = $(this);
var settings = $.extend({
// These are the defaults.
server: 'http://localhost/jQuery%20Gallery/images/galleries/homepage_gallery',
galleryName: 'Test',
galleryWidth: theObject.parent().width(),
galleryImageMargin: 20,
galleryImageColumns: 2,
imageQuality: 100
}, options);
var galleryImageWidth = settings.galleryWidth / settings.galleryImageColumns;
var imageUrl = settings.server;
var otherMargin = Math.round(settings.galleryImageMargin / 2);
var finalImageWidth = Math.round(galleryImageWidth - settings.galleryImageMargin);
var finalImageHeight = Math.round(galleryImageWidth / 1.4);
var finalGalleryWidth = settings.galleryWidth - settings.galleryImageMargin;
$(this).before('<style>'+$(this).selector+' li:nth-child('+settings.galleryImageColumns+'n+1) { margin-left: 0; } '+$(this).selector+' li:first-child { margin-left: 0; } '+$(this).selector+' { width: '+finalGalleryWidth+'px; margin: 0px; } '+$(this).selector+' li { display: inline-block; list-style: none; margin-left: '+settings.galleryImageMargin+'px; margin-bottom: '+otherMargin+'px; } </style>');
$.ajax({
url: imageUrl,
success: function(data){
console.log('SUCCESS');
var extension = '.jpg';
$(data).find("a:contains("+extension+")").each(function(){
// will loop through
var filename = $(this).attr("href");
$('<li></li>').html('<a href="'+imageUrl+'/'+filename+'" class="fancybox"><img src="thumbnail.php?src='+imageUrl+'/'+filename+'&q='+settings.imageQuality+'&h='+finalImageHeight+'&w='+finalImageWidth+'"/></a>').appendTo(theObject);
});
theObject.children('li:nth-child('+settings.galleryImageColumns+'n+1)').addClass('triggerMarginIE8');
},
failure: function(data){
console.log('FAIL');
}
});
};
}(jQuery));
据我所知,这在我的桌面上运行良好。然而,AJAX无法在iOS设备(可能还有其他设备)或同事的机器上正常启动,它说该文件夹已永久移动,但它没有!
有什么想法吗?由于console.log
答案 0 :(得分:1)
尝试在网址中输入相对路径。 :)
server: 'images/galleries/homepage_gallery', //your relative path...
var imageUrl = settings.server;
//Ajax call
$.ajax({
url: imageUrl,
success: function(data){
console.log('SUCCESS');
var extension = '.jpg';
$(data).find("a:contains("+extension+")").each(function(){
// will loop through
var filename = $(this).attr("href");
$('<li></li>').html('<a href="'+imageUrl+'/'+filename+'" class="fancybox"><img src="thumbnail.php?src='+imageUrl+'/'+filename+'&q='+settings.imageQuality+'&h='+finalImageHeight+'&w='+finalImageWidth+'"/></a>').appendTo(theObject);
});
theObject.children('li:nth-child('+settings.galleryImageColumns+'n+1)').addClass('triggerMarginIE8');
},
failure: function(data){
console.log('FAIL');
}
});