0

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
    });
});
mikhail
  • 5,019
  • 2
  • 34
  • 47
Harvs
  • 503
  • 1
  • 6
  • 18

2 Answers2

0

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:

Community
  • 1
  • 1
Rafael Almeida
  • 677
  • 7
  • 21
0

An easy way is by running your project/app in a local server such as Node.js or even more easy for you, by using the extension Chrome Dev Editor (developer preview) --

Chrome Dev Editor (CDE) is a developer tool for building apps on the Chrome platform - Chrome Apps and Web Apps. CDE has support for writing applications in JavaScript or Dart, and has Polymer templates to help you get started building your UI. CDE also has built-in support for Git, Pub and Bower.

Personally, I prefer run my local apps in Node.js

jherax
  • 5,238
  • 5
  • 38
  • 50