This question came up in a forum where I drop by now & then. It is also something that I recall answering previously on one or two occasions. So I thought I’d write about it here with a rudimentary example to provide a gist of how it works.
There’s no mystery or secret voodoo involved in having AJAX work in a Laravel app. On its own Laravel 4 (current version) doesn’t have any API for implementing AJAX, so you’ll need to do the footwork yourself. The basic concept that applies everywhere else applies here as well; grab the data from a HTML form, create an AJAX request and send it to server to a URL on which data is expected. Form data is retrieved on server just like any normal form data would be, the only key part is since you’re dealing with an AJAX request you can’t send back a normal View as response, you’ll need to make your own response with proper headers.
Note:I’ve assumed availability of jQuery in this example to avoid writing too much boilerplate. If you use any other library then you can use that as well, usage of jQuery is just to demonstrate the concept.
UPDATE: Updated the code example above to use Response::json() instead of the custom function which created a Response object and set the content type header to application/json.