0

I'm fetching data using backbone.js with the following code. The .get and .set commands work fine, but if I set JSON data, then use .save(), I get a 404 (Not Found) error.

var ExampleModel = Backbone.Model.extend({});
var example = new ExampleModel({});

example.url = "data/example.json";
example.fetch();

I'm using a basic server with the connect.js module:

var util = require('util'),
    connect = require('connect'),
    port = 8080;

connect.createServer(connect.static(__dirname)).listen(port);
util.puts('Listening on ' + port + '...');

and example.json looks like so:

{
"home": "new york",
"status": "married",
"kids": "one"
}

Is the problem with my server? Any help will be greatly appreciated.Thanks!

seal6105
  • 103
  • 1
  • 1
  • 5
  • can you share your `example` method on the server side? 404 means the server can't find the route `data/example.json` – neebz Feb 25 '13 at 19:31
  • how much experience in JavaScript and NodeJS do you have? I seems to me that you try to make use of some tutorial snippets. – pfried Feb 25 '13 at 19:36
  • @pfried I'm new at this and I'm trying to recreate whats being done in tutorial videos. – seal6105 Feb 25 '13 at 19:56
  • @nEEbz example.json is local file in the same folder as my application. – seal6105 Feb 25 '13 at 19:57
  • I think you are trying to get into this at a level which is too high for beginners. Without knowing about the basic technologies it is hard to understand how this really works. – pfried Feb 25 '13 at 20:01
  • @pfried, would you mind pointing me in the right direction please? A deeper understanding of Node and connect? – seal6105 Feb 25 '13 at 20:21
  • i think you should start with the Internet itself, how does the htt protocol work? This is very important because almost all the communication happens via HTTP. JavaScript + HTML + CSS is second. After this you can start playing with node and the frameworks. After this you can start developping JS applications. It is a long way to something that you would like to do in your question – pfried Feb 25 '13 at 20:32

1 Answers1

0

This might sound dumb but it is similar to a problem I had a few months ago with one of my backbone applications running with rails as a web server. Try defining the model 'url' adding a backlash at the beggining like this:

var ExampleModel = Backbone.Model.extend({
  url: '/data/example.json'
});

In my example I define the url attribute inside the model because I think it's cleaner but you can do differently if you like.

guzmonne
  • 2,490
  • 1
  • 16
  • 22