CodeIgniter Laravel PHP Example Javascript jQuery MORE Videos New
Need a Website Or Web Application Contact : +91 9437911966 (Whatsapp) Note: Paid Service

How to insert data using CodeIgniter, Ajax


<!DOCTYPE html>
<html lang="en">
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="">
  <script src=""></script>
  <script src=""></script>
  <script src=""></script>
<div class="container">
<h1 align="center">GPS Tracking</h1>
  <h2>Save Data</h2>
	<div class="alert alert-success alert-dismissible" id="success" style="display:none;">
	  <a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
	<div class="form-group">
      <label for="email">Name:</label>
      <input type="text" class="form-control" id="name" placeholder="Enter Name" name="name">
	<div class="form-group">
      <label for="email">Email:</label>
      <input type="email" class="form-control" id="email" placeholder="Enter Email" name="email">
	<div class="form-group">
      <label for="email">Phone:</label>
      <input type="text" class="form-control" id="phone" placeholder="Enter Phone" name="phone">
	<div class="form-group">
      <label for="email">City:</label>
      <input type="text" class="form-control" id="city" placeholder="Enter City" name="city">
    <button type="submit" class="btn btn-primary" id="butsave">Submit</button>
$(document).ready(function() {
	$('#butsave').on('click', function() {
		var name = $('#name').val();
		var email = $('#email').val();
		var phone = $('#phone').val();
		var city = $('#city').val();
		var password = $('#password').val();
		if(name!="" && email!="" && phone!="" && city!=""){
			$("#butsave").attr("disabled", "disabled");
				url: "<?php echo base_url("Crud/savedata");?>",
				type: "POST",
				data: {
					type: 1,
					name: name,
					email: email,
					phone: phone,
					city: city
				cache: false,
				success: function(dataResult){
					var dataResult = JSON.parse(dataResult);
						$('#success').html('Data added successfully !'); 						
					else if(dataResult.statusCode==201){
					   alert("Error occured !");
			alert('Please fill all the field !');


class Crud extends CI_Controller 
	public function __construct()
	public function register()
    public function savedata()
			echo json_encode(array(


class Crud_model extends CI_Model 
	function saverecords($name,$email,$phone,$city)
		$query="INSERT INTO `crud`( `name`, `email`, `phone`, `city`) 
		VALUES ('$name','$email','$phone','$city')";

Run the program on your browser with URL:


Here codeIgniter is my folder name. Put your folder name instead of codeIgniter.Rest of things are same.