Support the ongoing development of Laravel.io →
Views Forms
Last updated 2 weeks ago.
0

Your Laravel code is not the problem here. The problem may rather be in your JavaScript code that send the ajax request...

Try to remove the dataType and contentType options so that your ajax options look like that: $.ajax({type: "POST", data: myData, url: "http://tdc.dev/ajax";}); - you are not sending JSON content, but content encoded as "x-www-form-urlencoded" (which is the default content type).

( If you are using Chrome/Firefox, look in the developer tools to the network monitor and watch if your ajax request is correctly send to the server )

Last updated 2 weeks ago.
0

I'm not happy to remove the dataType: "json". I know, that I'm not sending json, but i need to recieve a response to my post in json... and I actually thought that dataType was the data format for the response and not the post/get format.

But still, not having anything else to go from I'll give it af try :-).

Last updated 2 weeks ago.
0

Thanks a bunch. Got a little confused in my response there. It was indeed the "contentType: 'application/json;". I changed that to contentType: 'charset=UTF-8' and now it works like a charm :-)

Last updated 2 weeks ago.
0

Scratch that! I removed contentType all together and it works!

Last updated 2 weeks ago.
0

Glad I could help you... ^^

NB: For UTF-8 encoding, from the jQuery docs:

POST data will always be transmitted to the server using UTF-8 charset, per the W3C XMLHTTPRequest standard
Last updated 2 weeks ago.
0

This saved me hours of Googling!!

0

Sign in to participate in this thread!

Full Stack Europe

Your banner here too?

ivermoller ivermoller ivermoller Joined 23 Aug 2014

Moderators

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

Your logo here?

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

© 2022 Laravel.io - All rights reserved.