Hallo Mann, ich versuche eine Live-Feed-Anwendung in Laravel 5.1 zu finden, wenn Benutzer ihre Beiträge einreichen können. Ich bin immer noch mit Ajax fest, weil ich Daten in DB usign Ajax Anfrage speichern möchte.Ajax submit form Laravel 5.1
Hier ist meine Form ist
{!! Form::open(array('url'=>'saveposts','method'=>'POST')) !!}
<div class="panel-body">
<textarea name="post" class="form-control share-text" rows="3" placeholder="Share your status..."></textarea>
</div>
<div class="panel-footer share-buttons">
<a href="#"><i class="fa fa-map-marker"></i></a>
<a href="#"><i class="fa fa-photo"></i></a>
<a href="#"><i class="fa fa-video-camera"></i></a>
<button type="submit" class="send-btn btn btn-primary btn-xs pull-right display-none" id="submit">Post</button>
{!! Form::close() !!}
ist hier Ajax-Skript
<script type="text/javascript">
$(document).ready(function(){
$('#submit').click(function(){
$.ajax({
url: 'saveposts',
type: "post",
data: {'post':$('input[name=post]').val(), '_token': $('input[name=_token]').val()},
success: function(data){
alert(data);
}
});
});
});
</script>
Die Route:
Route::post('saveposts', '[email protected]');
und das Verfahren in Steuer
public function savePosts() {
if(Requestjx::ajax()) {
$data = Input::all();
return Response::json([
'error' => false,
'insertedData' => $data
], 200);
}
}
Was ist falsch? Es hat nicht funktioniert. Jede Hilfe wird geschätzt. Danke
Was passiert, wenn Sie die URL im Ajax-Aufruf auf "/ saveposts" setzen? "Saveposts" ist keine gute Route Name BTW, nachschlagen Best Practices: http://www.vinaysahni.com/best-practices-for-a-pragmatic-restful-api#versioning – sandrooco
Hallo, vielen Dank für die Antwort. Nichts ändert sich, wenn ich/zur URL hinzufüge ... – rubenSousa
Hat es funktioniert? Wenn nicht, welche Fehler bekommst du? – cmac