csdn产品小助手 2016-10-21 10:45 采纳率: 0%
浏览 9

删除2个请求

Im using ajax to make a delete request, but for some reason, after making the first request to the right route, it makes another request to the current route. I only immplement the submission to the route of /products/id and not to the current route that is /galleries/id

My ajax is :

 //Deleting records


   $(".deleteProduct").click(function(){
        var id = $(this).data("id");
        var token = $(this).data("token");
        $.ajax(
                {
                    url: "/products/"+id,
                    type: 'DELETE',
                    dataType: "JSON",
                    data: {
                        "id": id,
                        "_method": 'DELETE',
                        "_token": '{{Session::token()}}',
                    },
                    success: function ()
                    {
                        console.log("it Work");
                        $('#delete').hide();
                    }
                });

        console.log("It failed");
        $('#delete').show();
    });

delete controller:

public function destroy($id)
    {
        $product = PhotoGallery::find($id);  
        $product->delete();
        Session::flash('success', 'The product was successfull deleted');
        return back();
    }

route:

Route::delete('products/{id}', 'PhotoGalleryController@destroy');

Note: The product im deleting in ajax is a list of products that are inside of a form

<form method="POST"  id="myform" action="/galleries/{{$gallery->id}}"  class="" role="form"  enctype="multipart/form-data" >
                        {{ method_field('PUT') }}
                        {{csrf_field()}}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 oracle集群安装出bug
    • ¥15 关于#python#的问题:自动化测试
    • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
    • ¥15 教务系统账号被盗号如何追溯设备
    • ¥20 delta降尺度方法,未来数据怎么降尺度
    • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
    • ¥15 再不同版本的系统上,TCP传输速度不一致
    • ¥15 高德地图2.0 版本点聚合中Marker的位置无法实时更新,如何解决呢?
    • ¥15 DIFY API Endpoint 问题。
    • ¥20 sub地址DHCP问题