Answer the question
In order to leave comments, you need to log in
Why is ajax request not working in laravel?
Here is the usual form:
<form action="" method="POST">
{{ csrf_field() }}
<div class="uk-margin">
<span class="uk-text-bold">Число:</span><input type="text" class="uk-input uk-form-width-small" name="bs">
</div>
<input type="hidden" value="{{ Auth::user()->name }}" name="user">
<button id="put_bet" class="uk-button uk-button-primary" type="button">Поставить</button>
</form>
<script type="text/javascript">
$( document ).ready(function() {
$("#put_bet").click(function(){
$.ajax({
url:'/ajax', //url в роуте
type:'POST',
data:{bs: 'cof_one'},
success:function(data)
{
$('.th-cof').html(data);
},
error: function(data)
{
console.log('2');
}
});
});
});
</script>
Route::post('/ajax','[email protected]')->name('bets.store');
public function store(Request $request)
{
$input = $request->all();
$bet = new Bet();
$bet->fill($input);
if($bet->save()){
Session::flash('store', 'Ваша ставка прошла!');
return redirect()->route('home');
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question