我有一个像这样简单的Ajax请求:
$.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)
}
})
问题是,如果用户在网页上登录,那么它位于(pending)
大约5分钟,然后500
错误,我不知道为什么会这样,我' m使用Express v3
,这基本上是请求的方式:
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();
}
}
})
}
我真的看不出任何错误,但由于某种原因,它只是位于(pending)
但是如果我没有登录而没有设置cookie,(从isAdmin function
移除post
)它有效。任何帮助都会很棒,这让我疯狂。
如果您对如何处理登录感到好奇:https://gist.github.com/anonymous/f458783ffdc45255f85d/raw/dd59d045b7fa76abc2dca458eea16702477c36d1/gistfile1.js
这实际上完全按照预期在localhost上运行,但当我将它推送到Nodejitsu时,它不起作用并且会出现此问题。