Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 我的快速页面只加载一次,第二次失败_Jquery_Node.js_Mongodb - Fatal编程技术网

Jquery 我的快速页面只加载一次,第二次失败

Jquery 我的快速页面只加载一次,第二次失败,jquery,node.js,mongodb,Jquery,Node.js,Mongodb,我有一个express页面,当它从jquery post请求收到post请求时,它会更新mongoose数据库中的一个文档,它会更新,但只有一次,当我输入另一个文档时,它会失败。我的猫鼬收藏中有两个文档,位置为温哥华 jquery页面 $(“#发送”)。单击(函数(){ var settings=JSON.stringify({ 类型:$(“#类型选项:选定”).text(), 产品名称:$(“#名称”).val(), collectionname:$(“#分组选项:选定”).text(),

我有一个express页面,当它从jquery post请求收到post请求时,它会更新mongoose数据库中的一个文档,它会更新,但只有一次,当我输入另一个文档时,它会失败。我的猫鼬收藏中有两个文档,位置为温哥华

jquery页面

$(“#发送”)。单击(函数(){
var settings=JSON.stringify({
类型:$(“#类型选项:选定”).text(),
产品名称:$(“#名称”).val(),
collectionname:$(“#分组选项:选定”).text(),
段:$(“#段选项:选中”).text(),
级别:$(“#级别选项:选定”).text()
});
控制台日志(设置);
$.ajax(“/logic”{
键入:“POST”,
contentType:'应用程序/json',
数据类型:“json”,
数据:设置
}).done(函数(){
console.log(“消息保存成功”);
}).失败(功能(错误){
console.log('未能保存消息:');
控制台日志(err);
console.log(err.stack);
}).always(函数(){
});
});

当您试图覆盖
vault
模型时,Mongoose出现了一个错误

每次向该端点发送POST请求时,您都在尝试创建
vault
模型。你不能这样做。尝试将定义移动到POST方法之外:

var stock = mongoose.model("vault",{
    name:{type:String},
    location:{type:String},
    minspent:{type:Number},
    minlength:{type:Number},
    member:{type:Boolean}
});

router.post('/logic',function(req,res,next){

    if (req.body.type == 'collection') {
        //edit corresponding attribute of all the items in that collection
        console.log("it is collection");
    } else if (req.body.type == "item") {
        //edit the corresponding attribute of the item
        product = req.body.productname;
        section = req.body.segment;

        stock.findOne({name:product}, function(err,doc) {
            if(err){console.log("failed to update doc");}
            doc.location = "The 6";
            doc.save();
        });
    }
    console.log("it went through");
    res.json({ ok: true });
});

当您试图覆盖
vault
模型时,Mongoose出现错误

每次向该端点发送POST请求时,您都在尝试创建
vault
模型。你不能这样做。尝试将定义移动到POST方法之外:

var stock = mongoose.model("vault",{
    name:{type:String},
    location:{type:String},
    minspent:{type:Number},
    minlength:{type:Number},
    member:{type:Boolean}
});

router.post('/logic',function(req,res,next){

    if (req.body.type == 'collection') {
        //edit corresponding attribute of all the items in that collection
        console.log("it is collection");
    } else if (req.body.type == "item") {
        //edit the corresponding attribute of the item
        product = req.body.productname;
        section = req.body.segment;

        stock.findOne({name:product}, function(err,doc) {
            if(err){console.log("failed to update doc");}
            doc.location = "The 6";
            doc.save();
        });
    }
    console.log("it went through");
    res.json({ ok: true });
});

这是一个500内部服务器错误响应代码。你在nodejs日志中看到了什么?上面就是,控制台日志的最后两行。其余的只是304个状态,这是500个内部服务器错误响应代码。你在nodejs日志中看到了什么?上面就是,控制台日志的最后两行。其余的只是304种状态