Note that there are some explanatory texts on larger screens.

plurals
  1. PONode js server for Ember Data
    text
    copied!<p>I have the sample "todo" ember application working with LSAdapter; now i'm attempting to use the RESTAdapter and get the json data from node js;</p> <p>In the Ember application i've done:</p> <pre><code>Todos.Store = DS.Store.extend({ revision: 13, url: "http://127.0.0.1" }); Todos.Todo = DS.Model.extend({ title: DS.attr('string'), isCompleted: DS.attr('boolean') }); </code></pre> <p>And this is the main route handler:</p> <pre><code>Todos.TodosIndexRoute = Ember.Route.extend({ model: function() { return Todos.Todo.find(); } }); </code></pre> <p>In ember data documentation they say that this should send an http request GET to url/todos, so in this case to:</p> <pre><code>http://127.0.0.1/todos </code></pre> <p>So i've made a Server with node js:</p> <pre><code>dispatcher.onGet("/todos", function(req, res) { bind.toFile('tmpl/todos.tpl', { id: "1", title: 'Just a try', is_completed: "false" }, function(data) { res.writeHead(200, {'Content-Type': 'text/html'}); res.end(data); }); }); </code></pre> <p>It uses httpdispatcher and bind modules from npm, and works because if i type in the browser:</p> <pre><code>//url in the browser 127.0.0.1/todos </code></pre> <p>i get:</p> <pre><code>{ "todo": { "id": 1, "title": Just a try, "is_completed": false } } </code></pre> <p>But if i execute the app in the browser (URL: file:///D:/Works/Web%20Resources/EMBER%20MVC%20FRAMEWORK/Prova_App/index.html) the todo "Just a try" is not loaded; inspecting with chrome, in the console tab, i can read an error that says "Failed to load resource file:///D:/todos"</p> <p>Can someone help to figure this out?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload