如何使用jQuery獲得目錄或文件夾的所有文件名和附加到重定向URL如何使用jQuery獲取目錄或文件夾中的所有文件名?
$(document).ready(function() {
GetDirectoryFiles();
});
function GetDirectoryFiles() { //function Definition for Get All FileNames Of Directory
$.ajax({
type: "GET",
url: "http://localhost:55304/TestViewsGoogleImgChanged/",
contentType: "application/html; charset=utf-8",
async: false,
crossDomain: true,
data: null,
dataType: "html",
success: function(data) {
var pagedata = $.parseHTML(data);
var tabledata = $.parseHTML(pagedata[9].innerHTML);
for (var i = 0; tabledata.length/2; i++) {
if (tabledata[i].textContent.indexOf('.cshtml') > 0) {
window.open('http://123.com/' + tabledata[i].textContent.split(".cshtml")[0], '_blank')
}
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus + '-----' + errorThrown);
}
});
}
假設你想獲取服務器上的文件,那麼你需要一個服務器端語言,如ASP或PHP,而不是JS。 –
基本上它是一個從服務器或本地使用DOM獲取數千個文件名的概念。你可以從這個特定的代碼訪問。 –
由於安全限制,無法訪問客戶端文件。正如我前面提到的,如果你想從服務器獲取它們,你需要一個服務器端語言 –