0

Using Chrome to run a sample knockout app that is for a Single page Application.

Referencing: http://learn.knockoutjs.com/#/?tutorial=webmail

Note: the sample app did not include a data (mailings) file, so I had to make one.

I am trying to load the data(mail) from a local file and I'm getting: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.

Per suggestions, I set Chrome to access files:

enter image description here

Here's where the local data file is located:

enter image description here

Here's the error:

enter image description here

My viewmodel: Note: normally it will dynamically locate the file based upon a folder chosen. For now I am hard coding it's location.

function WebmailViewModel() {
    // Data.
    var self = this;
    self.folders = ['Inbox', 'Archive', 'Sent', 'Spam'];

    self.chosenFolderId = ko.observable();
    self.chosenFolderData = ko.observable();

    // Whenever the user navigates to a folder, populate chosenFolderData by
    performing an Ajax request.
    self.goToFolder = function(folder) { 
        self.chosenFolderId(folder);

        $.get('C:\Dans\Work 2\Tech\Web Dev\Javascript and jQuery\Knockout.js\Tutorials\SPA\mail\Inbox\inbox.json', self.chosenFolderData);

        //$.get('/mail', { folder: folder }, self.chosenFolderData);
    };    

   // Show inbox by default.
    self.goToFolder('Inbox');
};

ko.applyBindings(new WebmailViewModel());

Here's the local data file content:

enter image description here

user3020047
  • 868
  • 1
  • 15
  • 45
  • Please use smaller screenshots that show the portion of the screen that you want to show us instead of the whole screen, and include the text of the error messages, JSON, etc. in your question as well. Regarding your issue [this answer](https://stackoverflow.com/a/18137280/1945651) suggests closing all running Chrome windows before starting it with this option. Have you done that? – JLRishe Oct 23 '17 at 18:04
  • Added smaller screenshots and Yes I have. – user3020047 Oct 23 '17 at 19:10
  • 2
    When you run something from your local file system it is not being served over a protocol like http[s]. You'll notice that it says `file://` that protocol does not support your actions. You will need to use some sort of web server, node, Apache, IIS, or something similar. – John Pavek Oct 23 '17 at 19:25
  • There is a consensus that I just need to add tis to my Google desktop icon's target. Yet it does not workd. "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --allow-file-access-from-files – user3020047 Oct 23 '17 at 23:54
  • @user3020047 Have you tried changing the path to `file:///C:/Dans/Work 2/Tech/Web Dev/Javascript and jQuery/Knockout.js/Tutorials/SPA/mail/Inbox/inbox.json`? – JLRishe Oct 24 '17 at 02:25

0 Answers0