@Patrick感謝您的建議,我發現您的答案有幫助。我結束了這樣的事情,我肯定不是最優的,但對於這個特定的項目工作正常。我借巨資從403 Forbidden error while making an ajax request
allow.php:
<?php
$filenameArray = array();
$summit = array();
$royce = array();
$soundview = array();
$merrit = array();
$hillcroft = array();
$all = array();
$handle = opendir(dirname(realpath(__FILE__)).'/assets/images/summit/slider/');
while($file = readdir($handle)){
if($file !== '.' && $file !== '..'){
array_push($filenameArray, "assets/images/summit/slider/$file");
array_push($summit, "assets/images/summit/slider/$file");
}
}
array_push($all, $summit);
$handle = opendir(dirname(realpath(__FILE__)).'/assets/images/royce/slider/');
while($file = readdir($handle)){
if($file !== '.' && $file !== '..'){
array_push($filenameArray, "assets/images/royce/slider/$file");
array_push($royce, "assets/images/royce/slider/$file");
}
}
array_push($all, $royce);
$handle = opendir(dirname(realpath(__FILE__)).'/assets/images/soundview/slider/');
while($file = readdir($handle)){
if($file !== '.' && $file !== '..'){
array_push($filenameArray, "assets/images/soundview/slider/$file");
array_push($soundview, "assets/images/soundview/slider/$file");
}
}
array_push($all, $soundview);
$handle = opendir(dirname(realpath(__FILE__)).'/assets/images/merrit-station/slider/');
while($file = readdir($handle)){
if($file !== '.' && $file !== '..'){
array_push($filenameArray, "assets/images/merrit-station/slider/$file");
array_push($merrit, "assets/images/merrit-station/slider/$file");
}
}
array_push($all, $merrit);
$handle = opendir(dirname(realpath(__FILE__)).'/assets/images/hillcroft-danbury/slider/');
while($file = readdir($handle)){
if($file !== '.' && $file !== '..'){
array_push($filenameArray, "assets/images/hillcroft-danbury/slider/$file");
array_push($hillcroft, "assets/images/hillcroft-danbury/slider/$file");
}
}
array_push($all, $hillcroft);
echo json_encode($all);
?>
然後我的JS:
$(document).ready(function(){/* Loop thru images folder */
var page = ['summit','royce','soundview','merrit-station','hillcroft-danburmer'].indexOf(window.location.href.split('/').pop())
console.log(page);
var url = "allow.php";
$.ajax({
url: url,
dataType: "json",
success: function(data) {
console.log(data);
console.log(data);
$.each(data[page], function(i,filename) {
console.log(filename);
var img = filename;
var arr = img.split('/');
console.log(arr[arr.length-3])
if(img.match(/\.(jpeg|jpg|gif|png)$/) != null && arr[arr.length-3] == window.location.href.split('/').pop()){
var html = '<li id="" style="background-image: url('+img+')"></li>';
$('#nikoSlider ul').append(html)
console.log(html);
} else { console.log("This is not a valid image type: " + img) }
})
nikoSlider();
}
});
//rows[i].children[2] $(rows[i].children[2]).find('attr', 'href').context.textContent $(rows[i].children[2]).text() rows[i].children[2].querySelector('a')['href']
})
請張貼出現在瀏覽器的開發工具的請求頭和響應頭時,該請求製作。處理請求的PHP腳本也會有所幫助。最後,控制對該PHP腳本的訪問的htaccess文件可能是罪魁禍首(特別是任何具有'[F]'標誌設置的'RewriteRule') – BeetleJuice
不知道哪裏是http://primaryman.com/pare/summit – Squirrl
是'http:// primaryman.com/pare/assets/images/summit/slider /'返回403你關心的網址嗎? – BeetleJuice