I've tried to fix this all morning and I can't seem to find any working method online.
I'm trying to do a simple ajax request to my Laravel controller and get the data it sends. I've simplified it to the maximum and I still get ERROR 500 with data "undefined".
It seems that every examples onlines are about Laravel 4.0, I'm not sure if they changed something or not but none seem to work. I also tried changing the route to "any" and it works on the direct access but not with the ajax request.
Thanks.
Controller :
<?php namespace App\Http\Controllers;
use Session, DB, Request;
class AjaxController extends Controller {
public function question()
{
print_r("Made It");
die();
}
}
Route :
Route::post('/ajax/question', 'AjaxController@question');
Javascript :
$.ajax({
url: "/ajax/question",
method: 'POST',
data: { 'answered': '1' },
processData: false,
contentType: false,
cache: false,
success: function(data) {
console.log(data);
console.log("success");
},
error: function(data) {
console.log(data);
console.log("error");
}
});
console.log(data) gives the following :
readyState
4
responseText
""
status
500
statusText
"Internal Server Error"
abort
function(e)
always
function()
complete
function()
done
function()
error
function()
fail
function()
getAllResponseHeaders
function()
getResponseHeader
function(e)
overrideMimeType
function(e)
pipe
function()
progress
function()
promise
function(e)
setRequestHeader
function(e, t)
state
function()
statusCode
function(e)
success
function()
then
function()
EDIT : If I change the request to GET it works properly. (Set route to any)