Jquery ajax php mysql crud example

We will do a little maintenance of data about customers, php mysql ajax jquery crud tutorial this will allow us to view, add, modify or delete your data. How ever we will use MySQL and PHP as it is how to try it on my web server. The explanation that I will be in general (non entrare in many details), so the comments can write their questions if they wish. I also want to clarify that I am not an expert in the use of jQuery, just to know something of what little I read of jQuery in Action, so perhaps the code go to sin of ignorance. Let us start

PHP CRUD with Search and Pagination using jQuery AJAX

This tutorial is for doing database CRUD operations with search and pagination feature by using jQuery and AJAX. In previous tutorial we have seen the CRUD,search and pagination without AJAX.

In this example we are creating jQuery AJAX functions for sending CRUD action request. With this request we are passing the AJAX parameters containing search keyword and current page information.

jQuery AJAX Search and Pagination jquery ajax php mysql crud example

We are having this function for handling database search and per-page navigation.

function getresult(url) {
$.ajax({
url: url,
type: "POST",
data: {rowcount:$("#rowcount").val(),name:$("#name").val(),code:$("#code").val()},
success: function(data){ $("#toys-grid").html(data); $('#add-form').hide();}
});
}

 

In this function we are sending total rows for creating pagination links. We are also sending the search keywords corresponding to the name and code column of the database.

 

In PHP page, these jQuery AJAX parameters are used to create HTML for listing database results as,

[banner_links-medio]

Today we will see how to make a crud with php using the extension PDO, as we will see no need to make the information entered by the user to prevent sql injection, since thanks to the consultations with the PDO extension these are protected automatically, will use jQuery and especially of jQuery ui and its more known as jQuery dialogs or modal windows and finally to follow making use of good practices this will making use pattern Singleton that we saw in this tutorial and what it does is that with a single instance we can make use of that object the times that we need to be creating new objects whenever we need something of the kind in question without, let’s see how to do all this in the simplest way possible.

[banner_evevi-alto]

jQuery Add Modify Delete Functions

We are having separate add, modify, delete functions using jQuery to access database via AJAX.

 

function add() {
var valid = validate();
if(valid) {
$.ajax({
url: "add.php",
type: "POST",
data: {name:$("#add-name").val(),code:$("#add-code").val(),category:$("#category").val(),price:$("#price").val(),stock_count:$("#stock_count").val()},
success: function(data){ getresult("getresult.php"); }
});
}
}
function showEdit(id) {
$.ajax({
url: "show_edit.php?id="+id,
type: "POST",
success: function(data){ $("#toy-"+id).html(data); }
});
}
function edit(id) {
var valid = validate();
if(valid) {
$.ajax({
url: "edit.php?id="+id,
type: "POST",
data: {name:$("#add-name").val(),code:$("#add-code").val(),category:$("#category").val(),price:$("#price").val(),stock_count:$("#stock_count").val()},
success: function(data){ $("#toy-"+id).html(data); }
});
}
}
function del(id) {
$.ajax({
url: "delete.php?id="+id,
type: "POST",
success: function(data){ $("#toy-"+id).html(''); }
});
}

 

We are getting form inputs for creating data-string to be passed to the PHP file. In add() and edit() functions we are calling jQuery validation before sending form inputs to a PHP file.

 

-crud-with-search-and-pagination-using-jquery-ajax.zip [7.5 Kb] (Downloads: 19)

[banner_abajo]

Rate this post