【发布时间】:2017-07-30 11:16:38
【问题描述】:
我有一个代码:
var bet = {
tournament: '',
bo: '1',
bet_team: '2',
betted: '3',
potential: '4',
percent: '5'
};
$.ajax({
type: 'POST',
url: '/api/makeBet/',
data: bet,
contentType: 'application/json',
dataType: 'json',
success: function(data) {
if(data.error) {
sweetAlert("Oops...", data.data, "error");
} else {
sweetAlert("Success!", data.data, "success");
}
},
error: function(html, status) {
console.log(html.responseText);
console.log(status);
}
});
但是当我尝试获取 $request->tournament 或其他内容时,我什么也得不到。
【问题讨论】:
-
控制器/路由的代码在哪里?
-
你能在你尝试使用
$request的地方展示Route和控制器方法吗? -
Route::post('/api/makeBet', 'APIController@makeBet')->name('makeBet');公共函数 makeBet(请求 $request)
-
尝试添加完整的网址,例如
url: 'localhost:8000/api/mekeBet' -
如果你想在成功函数中看到一些数据,你需要返回一些东西,例如在你的
makeBet方法return $request->all()
标签: php ajax laravel laravel-5