Support the ongoing development of Laravel.io →
Requests Views
Last updated 2 years ago.
0

What does console.log(data) return ?

Remove dataType: "json", temporarily and check the response.

0

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?

0
$.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"

Last updated 9 years ago.
0

@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. :)

0
success: function(response) {
    alert(response.data.data.key1);
}
Last updated 9 years ago.
0

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'] (?)
}
0

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!

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.