O'Reilly logo

Laravel Application Development Blueprints by Halil İbrahim Yılmaz, Arda Kılıçdağı

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Inserting data to the database with Ajax

In this application, we'll use the Ajax POST method for inserting data to the database. jQuery is the best JavaScript framework for these kinds of applications. jQuery also comes with powerful selector functions.

We have two forms in our HTML code, so we need to post them with Ajax to insert or update the data. We'll do it with jQuery's post() method.

We'll serve our JavaScript files under /public/assets/js, so let's create a todo.js file under this directory. First we need a request to add new tasks. The JavaScript code contains the following code:

$('#add_task').submit(function(event) { /* stop form from submitting normally */ event.preventDefault(); var title = $('#task_title').val(); if(title){ //ajax ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required