在脱机jquery应用程序中访问本地文件(Accessing local files in offline jquery app)

系统教程 行业动态 更新时间:2024-06-14 16:57:18
在脱机jquery应用程序中访问本地文件(Accessing local files in offline jquery app)

我是初学者尝试使用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/372​​333/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/

更多推荐

本文发布于:2023-04-12 20:29:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/10c621b58e98a76c2f36f9e1f6f63105.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   本地文件   Accessing   jquery   offline

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!