1

Backbone talking to node/express running locally os x 10.6.8. Trying to populate a clientside backbone model with fetch. Thinking I have fetch wrong. Most of app_stuff.js is cut-and-paste. Curious why node/express sees the request as OPTIONS instead of GET (or POST?) and if I have the terminology right. I think I can make it work like this but would rather pay the dues for some best practices while still an absolute newb.

backbone

(function($) {
    var Stuff = Backbone.Model.extend({

    });
    var Collec = Backbone.Collection.extend({
        model: Stuff,
        url: 'http://localhost:3000/stuff'
    });
    var nstuff = new Collec;
    nstuff.fetch(
        { data: $.param({ name: "helloworld"}) }
    );
})(jQuery);

app_stuff.js

var express = require('express')
  , routes = require('./routes')
  , stuff = require('./routes/stuff')
  , user = require('./routes/user')
  , http = require('http')
  , path = require('path');

var app = express();

app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));

if ('development' == app.get('env')) {
  app.use(express.errorHandler());
}

app.get('/', routes.index);
app.get('/users', user.list);
app.get('/stuff', stuff.index);
app.options('/stuff', function() { console.log("stuffed"); });

http.createServer(app).listen(app.get('port'), function(){
  console.log('Express server listening on port ' + app.get('port'));
});

terminal output

$ node timeline/app_stuff.js 
Express server listening on port 3000
stuffed
openquestions
  • 99
  • 3
  • 17
  • 3
    typically, an OPTIONS request is sent before the GET request as a preflight request to verify if the requester can access the domain...see the second answer here http://stackoverflow.com/questions/1256593/jquery-why-am-i-getting-an-options-request-insted-of-a-get-request ...whew abused that word request but I hope you get my drift – imrane Jun 01 '13 at 06:53
  • 1
    The app runs on localhost:3000? If not the is a cross domain request and sends the OPTIONS to check for allow origin headers – chchrist Jun 01 '13 at 21:04

0 Answers0