0

I have the following backbone model node that I am trying to use to fetch data from the server but at the moment I get a 404 error, I have checked my files and they seem to be correct

var app = app || {};

app.NotesModel = Backbone.Model.extend({
    url:'/usernotes',
    defaults: {             
        username:'',
        email:'',
        about:'',
        editorNote:''   
    }
});


app.NotesView = Backbone.View.extend({
    el:'#notes',
    events: {
        'click #save': 'save'
    },
    template1: _.template($('#about').html()),
    template2: _.template($('#facts').html()),

    initialize: function() {            
        app.NotesModel = new app.NotesModel({});    

        var email = $('#data-user').text();         

        app.NotesModel.fetch({data: {email: email},type:'GET' });

        this.render();
    },
    render: function() {

    },

This is what the route file looks like

app.get('/account/usernotes/', require('./views/account/usernotes/index').init);
app.get('/account/usernotes/:email', require('./views/account/usernotes/index').find);

and the functions for the routes

'use strict';

exports.init = function(req, res){
  if (req.isAuthenticated()) {
    //console.log(req.user.email);

    res.render('account/usernotes', 
      { data : {
          user : req.user.email
      }
    });
  }
  else {
    res.render('signup/index', {
      oauthMessage: '',
      oauthTwitter: !!req.app.config.oauth.twitter.key,      
      oauthFacebook: !!req.app.config.oauth.facebook.key,
      oauthGoogle: !!req.app.config.oauth.google.key
    });
  }
};

exports.find = function(req,res) {
   console.log('here');
   console.log(JSON.stringify(req));
}

Doing the console.log() doesn't give me any output at all.

Jordonias
  • 5,778
  • 2
  • 21
  • 32
Bazinga777
  • 5,140
  • 13
  • 53
  • 92
  • Show us your `server.js`/`index.js` and how you are using your routes file. – Jordonias Sep 18 '14 at 19:41
  • The last part of the code is the content of my index.js file. Also, my project is based on drywalljs if that helps. Finally, I am using a routes.js file with the routes mentioned in the middle of the code – Bazinga777 Sep 18 '14 at 19:42
  • Well you show your `routes` file but nothing about where you require that in your `index.js` are you doing something similar to `app.use(require('routes.js')(app));`? – Jordonias Sep 18 '14 at 19:47
  • @Bazinga777 check in browser console network log which address is calling when you fetching your model. Is it correct? – aleha_84 Sep 18 '14 at 19:57

1 Answers1

0

Here is a similar question.

Try this:

app.NotesModel.fetch({data: $.param({email: email}) });

or this:

app.NotesModel.fetch({data: {email: email}, processData: true });
Community
  • 1
  • 1
aleha_84
  • 8,309
  • 2
  • 38
  • 46