What does console.log(data) return ?
Remove dataType: "json", temporarily and check the response.
Thanks astroanu, but I've never used console.log(data) before. How do you use it?
I looked at my storage/logs files and could not see any errors there. I tried removing dataType: "json" but that did not make a difference. My javascript debugger does not show any errors either. My alert returns "undefined"
Am I missing something?
$.post( "path/to/my/controller", function(data) {
console.log(data);
});
but i think you error is "http://laravel.io/forum/11-14-2014-laravel-5-cant-post"
@poem is that the good old missing csrf token error ?
@djtechonline data['key1'] is undefined because data does not have a key by the name key1. console.log(data); should show what is being returned from the controller on your browser console. (ctrl + shift + j) You need to learn a bit about basic js debugging. :)
success: function(response) {
alert(response.data.data.key1);
}
starkyz said:
success: function(response) { alert(response.data.data.key1); }
I would say it's
success: function(data) {
alert(data.data.key1); // or data.data['key1'] (?)
}
Well, thank you all for your help. I was pretty sure it wasn't a token error, as I had already added the csrf-token to my .ajaxSetup in my master layout.
It turns out @othmanus had the solution for me. I was able to get the expected data response with data.data.key1
By the way, @astroanu, I am coding on Safari on a mac, so that key combination doesn't work for me. My debugger is launched with [ Option + Command + C ]. I will look more into debugging with console.log.
I really appreciate everyone's help. Thanks again!
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community