1

I am using mean to build a website. But when testing, it occurs a problem

Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. ------ jquery.js:9425

But I did not use XMLHttpRequest in my project. And the get request(see below) I make has no response, the server even only log the first console.log. I dong't know wether they are related. Thanks.

router.get('/login', function (req, res, next){
User.find({email: req.query.email}, function (err, user){
    console.log(req.query.email);
    if (err) {
        return next(err);
    } else if (!user) {
        return res.json({message: 'This email is not registered yet.'});
    } else {
        if (req.query.password != user.password) {
            return res.json({message: 'Password is not correct!'});
        } else {
            console.log(req.query.email);
            console.log(user);
            console.log(user.username);
            var token = auth.signToken(user._id, user.username, user.role);
            console.log(token);
            res.json({token: token, user: user});   
        };
    };
  });
});
vivian
  • 73
  • 1
  • 1
  • 6
  • 2
    Either 1. That isn't the code the warning relates to (note that whatever code it relates to is using jQuery to make the request, which in turn is using XMLHttpRequest). Or 2. Whatever `router` is, it's using XMLHttpRequest (via jQuery) under the covers, and somewhere, you've told `router` to make that request synchronous (or it's a terrible library that defaults to it, which seems unlikely). – T.J. Crowder Jan 17 '17 at 08:53
  • 1
    To find out where this request comes from, follow this [answer](http://stackoverflow.com/a/17210212/1640425) – Eddi Jan 17 '17 at 08:55
  • It is the xhr.open() in jquery.js that causes the problem, when it tried to open some referred files in the index.html, the async will be set to false, but what should i do? @RoryMcCrossan – vivian Jan 17 '17 at 09:42
  • I fixed it, I found that in jquery.js file, async is default to false, I changed it to true, and the problem fixed. – vivian Jan 17 '17 at 14:13

1 Answers1

0

In jquery.js file, there is an ajax.settings in jquery.extend(), and in ajax.settings, the async was set to false, just change it to true, and the problem will be resolved.

vivian
  • 73
  • 1
  • 1
  • 6