I Kommentar mit AJAX-Technologie hinzufügen bin versucht, aber ich habe einen Fehler: Failed to load resource: http://localhost:8888/blog/public/comment/add the server responded with a status of 500 (Internal Server Error)
Hier ist mein Code: Ausblick:AJAX Form Laravel Senden
{{ Form::open(array('method'=>'post','class'=> 'col-md-6','url' => '/comment/add', 'id'=>'comment')) }}
<input type="hidden" name="post_id" value="{{$id}}">
<div class="row">
<div class="inner col-xs-12 col-sm-12 col-md-11 form-group">
{{Form::label('name', 'Imię')}}
{{Form::text('username', null, array('class'=>'form-control', 'id'=>'name', 'name'=>'name'))}}
</div>
<div class="inner col-xs-12 col-sm-12 col-md-12 form-group">
{{Form::label('message', 'Wiadomość')}}
{{Form::textarea('message', null, array('class'=>'form-control', 'id'=>'message', 'name'=>'message', 'rows'=>'5'))}}
</div>
</div>
<div class="row">
<div class="col-xs-12 col-md-12 submit form-group">
{{Form::submit('Wyślij', array('name'=>'submit', 'class'=>'btn btn-orange'))}}
</div>
</div>
{{ Form::close() }}
Controller:
public function addComment()
{
$this->layout = null;
//check if its our form
if(Request::ajax()){
$name = Input::get('name');
$content = Input::get('message');
$comment = new Comment();
$comment->author = $name;
$comment->comment_content = $content;
$comment->save();
$postComment = new CommentPost();
$postComment->post_id = Input::get('post_id');
$postComment->comment_id = Comment::max('id');
$postComment->save();
$response = array(
'status' => 'success',
'msg' => 'Setting created successfully',
);
return 'yea';
}else{
return 'no';
}
}
AJAX:
jQuery(document).ready(function($) {
$('#comment').on('submit', function(e) {
e.preventDefault();
var name = $(this).find('input[name=name]').val();
$.ajax({
type: "POST",
url: host+'/comment/add',
}).done(function(msg) {
alert(msg);
});
});
});
A nd die letzten Routen:
Route::post('comment/add', '[email protected]');
Jeder hat eine Idee, wo ist das Problem und warum kann ich nicht mein Formular einreichen?
Wert des Hosts in Javascript? –
' 'so hat es' http: // localhost: 8888/blog/public' – Zobo
Ein 500-Fehler bedeutet, dass es wahrscheinlich eine nützliche Fehlermeldung in Ihrem Laravel-Protokoll ist. Überprüfen Sie dort. – ceejayoz