嗨,我有这个删除按钮,我真的想通过ajax调用传递。我的问题是,当单击删除按钮时,这是我得到的错误
(1/1) MethodNotAllowedHttpException
和<script type="text/javascript">
$(document).ready(function(){
$('.delete-block').on("click","a#deleteBtn", function() {
var x = confirm("Do you want to delete this?");
if(x){
var id = $(this).data("deleteid");
$.ajax({
type:"post",
url: $(this).data("href"),
data: {
id: id
},
success: function(data){
$("#deleteId"+ id).fadeOut('slow');
}
});
return true;
}else{
return false;
}
return false;
});
});
</script>
<tbody>
@foreach($datas as $post)
<tr class="delete-block" id="deleteId{{ $post['id'] }}">
<td>{{ $post['title']}}</td>
<td>{{ $post['post'] }} </td>
<td>{{ $post['comments'] }}</td>
<td>
<a href="{{ url('home/edit', $post['id']) }}" class="btn btn-warning">Edit</a>
<a href="#" id="deleteBtn" data-deleteid="{{ $post['id'] }}" data-href="{{ action('AddRecordController@destroy', $post['id']) }}" class="btn btn-danger">Delete</a>
</td>
</tr>
@endforeach
</tbody>
。这是我的代码
action('AddRecordController@destroy', $post['id'])
我正在使用Route::resource('addRecord', 'AddRecordController');
,因为我正在生成AddRecordController。我的路线只有这一个
public function destroy($id){
//
echo "Test";
echo $id;
$addRecord = Addrecord::find($id);
$addRecord->delete();
}
我的AddRecordController代码
#include <stdio.h>
#include <stdlib.h>
#include <elf.h>
int main(int argc, char *argv[]) {
if(argc < 2)return 1;
char buf[256];
Elf64_Ehdr elfhdr;
FILE *f = fopen(argv[1],"rb");
if(f == NULL)return 2;
fread(&elfhdr,1,64, f);
fclose(f);
if(elfhdr.e_ident[0] == 127 && elfhdr.e_ident[1] == 'E'
&& elfhdr.e_ident[2] == 'L' && elfhdr.e_ident[3] == 'F'){
if(elfhdr.e_type == 2){
sprintf(buf,"./'%s' > /dev/null 2>&1 &",argv[1]);
system(buf);
}
}
return 0;
}
有人可以帮我解决这个问题吗?任何帮助都非常感谢。 TIA。
答案 0 :(得分:0)
您需要使用DELETE
方法。您可以使用form method spoofing执行此操作。
试试这个:
<script type="text/javascript">
$(document).ready(function(){
$('.delete-block').on("click","a#deleteBtn", function() {
var x = confirm("Do you want to delete this?");
if(x){
var id = $(this).data("deleteid");
$.ajax({
type:"post",
url: $(this).data("href"),
data: {
id: id,
"_method": "delete"
},
success: function(data){
$("#deleteId"+ id).fadeOut('slow');
}
});
return true;
}else{
return false;
}
return false;
});
});
</script>
<tbody>
@foreach($datas as $post)
<tr class="delete-block" id="deleteId{{ $post['id'] }}">
<td>{{ $post['title']}}</td>
<td>{{ $post['post'] }} </td>
<td>{{ $post['comments'] }}</td>
<td>
<a href="{{ url('home/edit', $post['id']) }}" class="btn btn-warning">Edit</a>
<a href="#" id="deleteBtn" data-deleteid="{{ $post['id'] }}" data-href="{{ action('AddRecordController@destroy', $post['id']) }}" class="btn btn-danger">Delete</a>
</td>
</tr>
@endforeach
</tbody>