我是一個嘗試使用jquery構建應用程序的初學者(主要是離線),我正在使用chrome/firefox開發它我想擁有一個存儲了一些數據的本地.txt文件在它作爲一個數組。但是,我似乎無法訪問它。 ajax函數從未成功。在離線jQuery應用程序中訪問本地文件
(document).ready(function() {
local_list_dict = ['Example', 'Example 2', 'Example 3'];
online_list_dict = ['Park', 'running'];
$('#master_set').on('click', function() {
$.ajax({ //this does not work
url: "/local/pg/document1.txt",
success: function (data) {
alert('success');
},
});
for (i = 0; i < local_list_dict.length; i++) {
$('#local_list').append("<li class='idea_list'><a href='#player_1' rel='external'>" + local_list_dict[i] + "</a></li>");
}
;
$('#local_list').listview('refresh');
});
$('#home').hide().fadeToggle(500);
$('.idea_list').on('click', function() {
alert('debug')
var panelId = $(this).text(); // some function to pass player_1 the contents of the list
$('#chosen_list').html();// some function that takes panelId and uses it to choose the relevant .txt file
});
});
如果您正在關閉文件協議,而不是本地服務器,它有不同的安全規則。您需要更改瀏覽器設置才能訪問本地文件。 http://www.chrome-allow-file-access-from-file.com/ – epascarello 2015-04-02 12:49:35
爲什麼不將數據保存在cookie中? – Banana 2015-04-02 12:50:27
http://localhost/local/pg/document1.txt在瀏覽器中工作嗎? – vekah 2015-04-02 12:50:28