javascript - Ajax request not working when signed in, works when not signed in -
i have ajax request simple this:
$.ajax({ type: "post", url: "/admin.html", data: datastring, success: function(data) { if(data.error) { $('#alertt').text(data.error); $('#alertt').show(); $('#alertt').fadein().delay(2000).fadeout('slow'); } else if (data.success) { var lati = $('#route_latitude').val(); var longi = $('#route_longitude').val(); increment(); setmarker(lati, longi); $('#alertt').text(data.success); $('#alertt').show(); $('#alertt').fadein().delay(2000).fadeout('slow'); } }, error: function(jqxhr, textstatus, errorthrown) { console.log(textstatus + " " + errorthrown) } })
the problem is, if user signed in on webpage, sits @ (pending)
5 minutes 500
errors, i'm not sure why is, i'm using express v3
, how request goes:
var isadmin = function(req, res, next) { helper.isadmin(req, res, next); } app.post('/admin.html', isadmin, admin.new); exports.isadmin = function(req, res, next) { db.users.find({'remembertoken': req.cookies.remembertoken}, function(err, founduser) { if (err) { console.log('we have error' + err) } else { if (founduser.length === 0) { console.log('somebody attempted view admin page without account.') res.render('index', { 'title': 'home page'}) } else if (founduser[0].admin === 0) { console.log('a non-admin user account tried log admin page: ' + founduser[0].email); res.render('index', { 'title': 'home page' }); } else if (founduser[0].remembertoken === req.cookies.remembertoken) { console.log('admin viewing admin page.'); next(); } } }) }
i can't see wrong, yet reason sits @ (pending)
if not-logged in no cookie set, (with isadmin function
removed post
) works. great has been driving me nuts.
if you're curious how sign in handled: https://gist.github.com/anonymous/f458783ffdc45255f85d/raw/dd59d045b7fa76abc2dca458eea16702477c36d1/gistfile1.js
this works intended on localhost, when push nodejitsu, doesn't work , problem happens.
Comments
Post a Comment