ajax get 405错误,Laravel 5.3中的Ajax:不允许GET方法(405错误)(Ajax in Laravel 5.3 : GET method not allowed (405 e...

I have a list of animals profiles (ID cards). When I click on one of them while logged in as an Admin, I access a page with more details and several pictures. There, I can edit the animal profile (POST method), and I would also like to be able to delete a picture by clicking on it. I'm trying to use Ajax to do that, but I'm unable to complete the process. My code so far :

Route::get('/edition-adoption/{animal}', 'AnimalsController@editAdoption')

->where('animal', '[0-9]+');

Route::post('/edition-adoption/{animal}', 'AnimalsController@updateAdoption');

Route::get('/edition-adoption/{folder}/{file}/delete', ['uses' => 'AnimalsController@deletePicture', 'as' => 'delete']);

View :

{{ csrf_field() }}

/*several fields to update*/

edit_profile($animal->id);

?>

/*other fields & submit button*/

Controller :

public function editAdoption (Animal $animal) {

return view('administration/edition-adoption',['animal' => $animal]);

}

public function deletePicture($file, $folder) {

$path = public_path('js/slider_images/Adoption/Profile/'.$folder.'/'.$file);

unlink($path);

}

public function updateAdoption (Request $request) {

/*several update requests*/

}

Helper :

function edit_profile($current_id) {

$paths = File::Files('js/slider_images/Adoption/Profile/'.$current_id);

if (count($paths)==0) {

echo

"

Aucune image

";

}

else {

foreach($paths as $path)

{

$filesinfo[] = pathinfo($path);

}

foreach ($filesinfo as $file) {

$current_basename = $file['basename'];

echo

"%22.%24current_basename).%22&nbsp&nbsp";

}

}

}

imageSrc.js (Ajax) :

function getImgSrc(param){

var imgSrc = $(param).attr("src");

var myarr = imgSrc.split("/");

var arrlen = myarr.length;

var id = myarr[arrlen-2];

var myvar = myarr[arrlen-1];

var result = confirm("Voulez-vous vraiment supprimer cette image ? Cette action est irréversible.");

if (result) {

$.ajax({

url: 'delete',

headers: {

'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')

},

data: {'folder': id, 'file' : myvar},

success: function (response) {

alert('Image supprimée !');

},

error: function () {

alert('Erreur. Veuillez réessayer.');

}

});

}

}

The confirmation alert works fine, but when I click on OK, the following exception appear :

Any idea(s) on how to solve this problem?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值