Currently, I am attempting to use ajax to send a message (with instant messenger) to the server, save the message and update with the message. Whenever I submit it, however, it returns a 500 Internal Server Error and if I change the token:$('#token')
to '_token' : token
as I have seen here, it times out completely.
The ajax
function submitIMchat(){
console.log($('#IMchat-submit-message').val());
console.log($('#token').val());
$.ajax({
url: "{{ action('MessagesController@sendAjaxMessage') }}",
type: "post",
dataType:'json',
data: ({ token:$('#token'), id:{{ Session::get('IMchatuser') }}, message:$('#IMchat-submit-message').val() }),
success: function(data){
console.log(data);
return false;
}
})
.error(function(data) {
var errors = data.responseJSON;
console.log('server errors',errors);
});
};
The form
<form action="#" onsubmit="submitIMchat()">
<input type="hidden" id="token" value="{{ csrf_token() }}">
<input id="IMchat-submit-message" type="text" style="width:100%;">
</form>
The route
Route::post('sendAjaxMessage', 'MessagesController@sendAjaxMessage');
Can anyone tell what might be wrong with my code here? If any other information is needed, please let me know. Note: I did not include sendAjaxMessage as it does not execute the function yet.
Thanks.