使用 ajax 和拉拉维尔删除动态行

我有一张发票,当我想编辑时,我希望能够删除一些行,要么在数据库中找到该行,要么添加该行,但单击“添加”按钮。所以我必须根据这个条件删除这个行

  1. 如果在数据库中找到,则删除行

  2. 删除/删除行(如果添加了新行)(无需签入 DB,因为您添加了新行)

以下是我的发票,显示行包含来自DB的数据,而行没有数据(新增)

http://img.mukewang.com/6335498200012d4611740755.jpg

所以我已经删除了在DB中找到的行,并且我想按照我的以下代码应用第二个条件。


 $(document).ready(function () {

              $("body").on("click",".remove",function(e){


              var last=$('#tdy tr').length;



              if(last==1){

                alert("you can not remove last row, Otherwise Delete The Order Number!");

              }


              //here i tried the second condition

               else if(iddata=null){



                $(this).parent().parent().remove();


                   }



                else{

                  if(!confirm("Do you really want to delete this?")) {

                   return false;

                 }


                 e.preventDefault();

            // var id = $(this).attr('data-id');

            var id = $(this).data("id");


            var token = $("meta[name='csrf-token']").attr("content");

            var url = e.target;


            $.ajax(

            {

                  url: "Loading/"+id, //or you can use url: "company/"+id,

                  type: 'DELETE',

                  data: {

                    "id": id,

                    "_token": token,

                  },

                  success: function (response){


                   if ( data['success'] ) 

                   {

                     alert(data['success']);

                     location.reload();

                   } 


                 }

               });

            return false;

          }


        });

我怎么能解决这个问题,有些人可以帮助我


叮当猫咪
浏览 107回答 1
1回答

慕姐8265434

请更改此设置 else if(iddata = null)为此else if(iddata === null) // or else if(!iddata)在这里,您需要使用相等运算符 ==,甚至更好的是单位运算符 === 而不是赋值运算符=关于在删除您可以使用的项目时重新加载页面location.reload(); return false;在函数的末尾,这是因为无论删除的类型如何,这两个操作最终都会刷新页面
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript