【发布时间】:2017-02-15 15:29:00
【问题描述】:
我正在尝试通过 ajax post call 将视图中的 dta 发送到 Laravel 控制器。它给了我错误 404 not found 我检查了很多东西但我找不到错误。
class AttemptController extends Controller {
public function postSavegame(Request $request) {
$data = $request->all();
print_r($data);
//insert data to db
$id = $this->model->insertRow($data, $request->input($data));
// Insert logs into database
if ($id != '') {
\SiteHelpers::auditTrail($request, 'New Data with ID ' . $id . ' Has been Inserted !');
echo('Done');
}
}
}
这是视图中的 AJax:
$.ajax({
method: 'POST',
url: "{{ URL::to('Attempt/savegame') }}",
data: {
quiz_id: localStorage.quiz_id,
user_id: "{{Session::get('uid')}}",
total_score: localStorage.achivePoints, // a JSON object to send back
success: function (response) { // What to do if we succeed
console.log(response);
},
error: function (jqXHR, textStatus, errorThrown) { // What to do if we fail
console.log(JSON.stringify(jqXHR));
console.log("AJAX error: " + textStatus + ' : ' + errorThrown);
}
},
});
这是我的路线条目
Route::post("gamesave", "AttemptController@gamesave");
【问题讨论】:
-
你的ajax中有
savegame,你的路由中有gameSave。 -
它的影响
-
不,我的意思是,在您的 ajax 调用中,您有一部分 URL 为
savegame,但路由有gamesave。它没有找到路线,因为它们不一样。