SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Feb 2013
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Chapter 1: Not able to submit form; no logs?

    Hello, my form is not submitting. And the page does nothing upon hitting submit. The browser goes into its loading mode (spinny wheel in the tabs of chrome).

    I'm not sure why this is happening, but node is not throwing any errors in the console.

    Are there logs available for me to trouble shoot this issue? I do not know if it is because of a typo in my code, work proxy, etc.

    Thanks!

  2. #2
    SitePoint Author
    Join Date
    Nov 2012
    Posts
    48
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    After your form is posted you should land here:

    app.post('/signup', function(req, res) {
    var username = req.body.username;
    var password = req.body.password;
    User.addUser(username, password, function(err, user) {
    if (err) throw err;
    res.redirect('/form');
    });
    });
    You can put various

    console.log
    statements in to track what is happening. Similarly with:

    /models/User.js
    The error is likely occurring in one of those two places

  3. #3
    SitePoint Member
    Join Date
    Aug 2013
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Having the same issue.. think it has something to do with the instance.save function in addUser in User.js. Not sure what to do.

  4. #4
    SitePoint Member
    Join Date
    Aug 2013
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well I'm not sure what I did, but it's workign now. I made a new user for the database, logged out and logged back in to MongoLab, changed some lines then changed them back, etc ect. but now it seems to be working and I'm pretty sure it's exactly how it was in the book save for I think there was a typo in the url of the database connection but I had already taken care of that. Hmm. I don't know. Well, at least it works!

  5. #5
    SitePoint Member
    Join Date
    Oct 2013
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I had the same issue, until I cheked with a difftool I found that in the file lib/db.js you have to call the connect function. Chek: https://github.com/spbooks/NODEJS1/b...tion/lib/db.js on line 11.

  6. #6
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,194
    Mentioned
    17 Post(s)
    Tagged
    5 Thread(s)
    I'm having the same issue on a windows 7 machine. I did determine that it is the instance.save call causing the issue since the second log message is never seen. Could this possibly be some type of firewall issue? Do I need to install mongodb on my machine or should everything just work with mongoose?

    User.js
    Code JAVASCRIPT:
    ...
     
    // Add user to the database
    function addUser(username, password, callback) {
      var instance = new MyUser();
      instance.username = username;
      instance.password = password;
     
      console.log("Add new user 1");
     
      instance.save(function(err) {
     
        console.log("Add new user 2");
     
        if(err) {
          callback(err);
        } else {
          callback(null, instance);
        }
      });
     
    }
    The only code I hate more than my own is everyone else's.


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •