Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.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
Javascript Ajax删除请求似乎只删除列表中的第一项_Javascript_Jquery_Node.js_Ajax_Express - Fatal编程技术网

Javascript Ajax删除请求似乎只删除列表中的第一项

Javascript Ajax删除请求似乎只删除列表中的第一项,javascript,jquery,node.js,ajax,express,Javascript,Jquery,Node.js,Ajax,Express,我一直在为不同的项目重用这些代码,但对于这一个,它似乎不起作用。我正在使用Express和Mongoose,并在其中存储大学课程详细信息列表。这是模式 exports=module.exports=function(app,mongoose){ var moduleSchema=newmongoose.Schema({ 透视:{type:String,默认值:''}, 模块名称:{type:String,必需:true}, 模块代码:{type:String,必需:true}, 描述:{typ

我一直在为不同的项目重用这些代码,但对于这一个,它似乎不起作用。我正在使用Express和Mongoose,并在其中存储大学课程详细信息列表。这是模式

exports=module.exports=function(app,mongoose){
var moduleSchema=newmongoose.Schema({
透视:{type:String,默认值:''},
模块名称:{type:String,必需:true},
模块代码:{type:String,必需:true},
描述:{type:String}
});
moduleSchema.plugin(需要('./plugins/pagedFind');
moduleSchema.index({pivot:1});
moduleSchema.index({module_name:1});
moduleSchema.index({module_代码:1});
moduleSchema.index({description:1});
moduleSchema.index({search:1});
moduleSchema.set('autoIndex',(app.get('env')='development');
app.db.model('Module',moduleSchema);

};由于
id
在HTML页面中必须是唯一的,因此请使用类而不是
id
,并将删除功能与之绑定

// use .deleteModule instead of #deleteModule
$(".deleteModule").on('click', function(e){
    e.preventDefault();
    var deleteId = $(this).data('delete'); // here use this instead of  using id #deleteModule
    $.ajax({
        url: '/modules/delete/'+ deleteId,
        type:'delete',
        success: function(result){
            console.log(result);
        },
        error: function(error){
          console.log(error);
        }
    });
    window.location = '/modules/';
});
在HTML模板中添加class
deleteModule
like

ul.list-group
    each module, i in data
      li.list-group-item
        strong #{module.module_code} - #{module.module_name}
        hr
        p #{module.description}
        a(href='/modules/edit/#{module._id}', class='btn btn-primary') Edit
        a(id='deleteModule', data-delete='#{module._id}', class='btn btn-danger pull-right deleteModule', href="#") Delete