lundi 23 mai 2016

Laravel 5: AJAX Requests & Validation

Laravel 5.2 docs state:

AJAX Requests & Validation

In this example, we used a traditional form to send data to the application. However, many applications use AJAX requests. When using the validate method during an AJAX request, Laravel will not generate a redirect response. Instead, Laravel generates a JSON response containing all of the validation errors. This JSON response will be sent with a 422 HTTP status code.

Src: http://ift.tt/1Ts6xC1

However, this doesn't seem correct. A simple CURL call to a route using validation, still returns HTML/a redirect:

curl -X POST -H "Content-Type: application/json" 
-H "Cache-Control: no-cache" 
-d '{}' "http://ift.tt/1YT4ipK"

The response of the above is HTML, and a redirect. It's not JSON.

Even this page: http://ift.tt/1Ts6UfY states:

Retrieving JSON Input Values

When sending JSON requests to your application, you may access the JSON data via the input method as long as the Content-Type header of the request is properly set to application/json.

So what have we missed? What is the solution?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1YT4hlM
via IFTTT

Aucun commentaire:

Enregistrer un commentaire