I have an Ajax request that is simple like 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, that if the user is signed in on the webpage, then it sits at (pending) for about 5 minutes then 500 errors, I'm not sure why this is, I'm using Express v3 and this is basically how the 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 an error' + err) } else {
if (foundUser.length === 0) {
console.log('Somebody attempted to view the Admin page without an account.')
res.render('index', { 'title': 'Home Page'})
} else if (foundUser[0].admin === 0) {
console.log('A non-admin user account tried to log into the 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 really can't see anything wrong, yet for some reason it just sits at (pending) but if I do it not-logged in with no cookie set, (with the isAdmin function removed from the post) it works. Any help would be great this has been driving me nuts.
If you're curious how the sign in is handled: https://gist.github.com/anonymous/f458783ffdc45255f85d/raw/dd59d045b7fa76abc2dca458eea16702477c36d1/gistfile1.js
This actually works completely as intended on localhost, but when I push it to Nodejitsu, it doesn't work and this problem happens.