nodejs上的Ajax错误

时间:2016-01-06 03:23:04

标签: javascript jquery ajax node.js

我正在使用nodejs开发webapp,我使用request.session创建寄存器,并且我使用ajax发出请求,当我使用条件获取某些信息(ID)时,我收到错误。

router.post("/admin", function(request, response){  
    var data = {};

    sess = request.session;
    sess.username = request.body.input_user_admin;
    sess.password = request.body.input_password_admin;

    if(sess){
        // Verificate user existence (in a database) to login
        if(loginFunctions.userIsRegistered(sess.username, sess.password, admins)){
            for(var i=0; i<admins.length; i++){
                if(admins[i].name == sess.username && admins[i].password==loginFunctions.md5(sess.password)){
                    i = admins.length;
                    data["devices"] = devices;
                    data["users"] = users;
                    data["sess"] = sess;
                    response.render('admin', data);
                }
            }
        }
        else{
            response.redirect('/adminLogin');
        }
    }

    else if(request.body["idUserToDelete"]){
        console.log("SISAS ÑOTE");
        Users.remove({"_id": request.body["idUserToDelete"]}, function(err){});
        updateUsersReading();
        data["devices"] = devices;
        data["users"] = users;
        //response.send(data);
    }

    else if(request.body["dataCodes"]){
        updateDataFromCodesAdmin(request.body);
        updateDevicesReading();

        data["devices"] = devices;
        data["users"] = users;

        response.render('admin', data);
    }

    else if(request.body["newDevices"]){
        addNewDevicesToDB(request.body, sess, response);
        updateDevicesReading();
        data["devices"] = devices;
        data["users"] = users;
        response.render('admin', data);
    }

    else{
        response.redirect('/adminLogin');
    }
});

这是错误

  

错误:发送后无法设置标头           在ServerResponse.OutgoingMessage.setHeader(http.js:691:11

一般情况下,如何将对ajax请求的回复等数据发送到视图(admin.jade),所以我使用response.send(数据),我有问题?

0 个答案:

没有答案