【发布时间】:2018-06-05 22:59:15
【问题描述】:
出于测试目的,我在 freehosting 上托管了我的网站,一切正常,但 Ajax 会删除。当我单击删除时,删除功能通过并删除所有内容,但由于某种原因它返回 500 错误。在本地它可以正常工作。
Route::delete('/admin/deleteRound', 'AdminCyclesController@deleteRound')->name('admin.deleteRound');
和
$.ajax({
type: "POST",
url: urlDeleteRound,
data: {cycle_id: cycle_id, round: round, _token: token, _method: 'delete'}
}).success(function (response) {.....});
我尝试了所有可以在网上找到的方法,但都没有成功。有没有办法解决这个问题,或者至少有办法找出问题所在?
已编辑 - .log
我不知道该怎么做。
local.ERROR: SQLSTATE[HY000]: 一般错误(SQL: DELETE FROM
cycle_teamwhere cycle_team.cycle_id=9 and cycle_team.round=1) {"userId":1,"email":"xxxxxx@gmail .com","exception":"[object] (Illuminate\Database\QueryException(code: HY000): SQLSTATE[HY000]: 一般错误(SQL: DELETE FROMcycle_teamwhere cycle_team.cycle_id=9 and cycle_team.round= 1)在/storage/ssd5/708/6079708/laravel/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664,PDOException(代码:HY000):SQLSTATE[HY000]:/storage/的一般错误ssd5/708/6079708/laravel/vendor/laravel/framework/src/Illuminate/Database/Connection.php:332)
编辑 2 - 执行删除的代码
public function deleteRound(Request $request){
$round=$request['round'];
$id=$request['cycle_id'];
DB::select("DELETE FROM `cycle_team` where cycle_team.cycle_id=$id and cycle_team.round=$round");
$teams = DB::select("SELECT teams.id, teams.title,sum(ct.points) + sum(ct.is_winner) + sum(ct.is_over) as points, sum(ct.points) + sum(ct.is_winner) + sum(ct.is_over)-Min(ct.points + ct.is_winner + ct.is_over) as minpoints, COUNT(teams.id)-1 as number FROM `teams`INNER JOIN cycle_team as ct on teams.id =ct.team_id INNER JOIN cycles as c on c.id = ct.cycle_id where ct.cycle_id =$id > 0 GROUP BY ct.cycle_id, ct.team_id, teams.title, teams.id order by points desc");
return response()->json(['teams'=>$teams]);
}
解决方案
DB::select("DELETE FROM `cycle_team` where cycle_team.cycle_id=$id and cycle_team.round=$round")
正在制造问题,使用 Builder 解决了问题
DB::table('cycle_team')->where('cycle_id', id)->where('round', $round)->delete();
【问题讨论】:
-
检查 laravel.log 看看是什么导致了错误
-
请检查编辑,我迷路了。
-
你能贴出执行删除的代码吗?
-
已发布,有什么见解吗?复制到服务器时是否有可能某些文件损坏?
-
您是否尝试过使用
QueryBuilder执行删除? -DB::table('cycle_team')->where('cycle_id', $id)->where('round', $round)->delete();
标签: ajax laravel shared-hosting