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:
Here's where the local data file is located:
Here's the error:
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: