我有一个代码:
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
或其他内容时,我什么都没得到。
答案 0 :(得分:2)
发布代码可以有很长的路要走;同时,这可能会有所帮助:
路线...
Route::post('/api/makeBet/', 'YourController@index');
...控制器
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class YourController extends Controller
{
//
public function index(Request $request)
{
$tournament = $request->tournament //gives tournament
}
}
答案 1 :(得分:1)
这对我有用
<li class="nav-item dropdown">
<a href="#" id="navbar-inquiries-dropdown" class="nav-link dropdown-toggle" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" v-pre>
<i class="fas fa-bell"></i>
// here add badge????
</a>
<ul class="nav-item dropdown-menu" role="menu" aria-labelledby="navbar-inquiries-dropdown">
<li class="nav-item">
<a class="dropdown-item" href="{{ route('inquiry.index') }}">
Requests
</a>
</li>
</ul>
</li>
答案 2 :(得分:0)
您需要使用JSON.stringify首先将对象序列化为JSON,然后指定内容类型,以便服务器理解它的JSON。这应该可以解决问题:
var bet = {
tournament: '',
bo: '1',
bet_team: '2',
betted: '3',
potential: '4',
percent: '5'
};
$.ajax({
url: '/api/makeBet/',
method: 'post',
contentType: 'application/json',
data: JSON.stringify(bet),
success: function(data) {
// so something
}
})