我是初学者尝试使用jquery来构建应用程序(主要是离线),我正在使用chrome / firefox开发它我想要一个本地.txt文件,其中一些数据作为数组存储在其中。 但是,我似乎无法访问它。 ajax功能永远不会成功。
(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 }); });I'm a beginner trying to use jquery to build an app (mostly offline), I'm developing it using chrome/firefox I want to have a local .txt file with some data stored in it as an array. However, I can't seem to access it. The ajax function never succeeds.
(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 }); });最满意答案
我试过做同样的事情,但我没有得到一些安全规则的好结果。 有一些技巧可以帮助您尝试,但最好的办法是在本地服务器上运行您的脚本(您可以使用WampServer或其他工具)。 一些有用的链接可以帮助您:
https://stackoverflow.com/a/372333/3126013 https://stackoverflow.com/a/19902919/3126013 http://www.html5rocks.com/en/tutorials/file/dndfiles/I tried do the same thing, but I don't got some good results duo the security rules. There are some tricks to help you to try, but the best to do is run your script in a local server (you can do it with the WampServer or other tools). Some interesting links that can help you:
https://stackoverflow.com/a/372333/3126013 https://stackoverflow.com/a/19902919/3126013 http://www.html5rocks.com/en/tutorials/file/dndfiles/更多推荐
发布评论