Skip to main content

MVC AJAX Form display



This method will easy to understand ajax data pass


View/home



<html>
    <head>
        <title>Submit form</title>
        <script src="http://localhost/js/jquery.min.js" type="text/javascript" ></script>

        <script type="text/javascript">

            $(document).ready(function() {
                $('.jsForm').on('submit', function(form) {
                    form.preventDefault();

                    $.ajax({
                        url: 'index.php/home/insert',
                        type: 'POST',
                        data:
                                {
                                    username: $('#username').val(),
                                    password: $('#password').val()
                                },
                        success: function(data) {
                            $(".jsError").html(data).hide("slow");

                            console.log(data);
                        }
                    });



                });
            });

        </script>
    </head>
    <body>
        <div class="jsError"></div>
        <?php echo form_open('home/insert', array("class" => 'jsForm')); ?>

        <input type="text" name="username" id="username"/>
        <input type="text" name="password" id="password"/>
        <input type="submit" value="save" />

        <?php echo form_close(); ?>
    </body>
</html>


Controller/Home

<?php

class Home extends CI_Controller {

    public function view($page = 'home') {
        $this->load->library('form_validation');
        $this->load->view('home/' . $page);
    }
 
    public function insert(){
        $user=$this->input->post('username');
        $pass=$this->input->post('password');
        echo $user." ".$pass;
    }


}

Comments

Popular posts from this blog

Ministry of Higher Education Project : SLIATE (live project)

ABOUT SLIATE Our Mission  "Creating Excellent Higher National and National Diplomates with Modern Technology for Sustainable Development" Our Vision "To Become the Centre of Excellence in Technological Education" As per the recommendations of the Committee appointed by Prof. Wiswa Waranapala, Deputy Minister of Higher Education in 1994, the Sri Lanka Institute of Advanced Technical Education (SLIATE) was formed in 1995, under the Sri Lanka Institute of Advanced Technical Education Act No. 29 of 1995, In 2001 the name of the institution was amended as Sri Lanka Institute of Advanced Technological Education, (SLIATE). It functions as an autonomous Institute for the management of Higher National and National Diploma courses. The main purposes of establishing SLIATE were to reform and restructure the entire technical and vocational education system in relation to the changing needs of economic development, to meet manpower requirements of natio...

Micro Loan Banking Management System

Android SQLite Database 1

Using Android Studio Crating a Database (SQLite) 1. NEW PROJECT 2.CREATE  A CLASS NAME CALL (DB.class) 3.import SQLiteDatabase    import SQLiteOpenHelper SCREEN SHOT OF CODE (IMAGE) CODE (TEXT) Bellow package com.example.rimzan.j2program ; import android.content.Context ; import android.database.sqlite.SQLiteDatabase ; import android.database.sqlite.SQLiteOpenHelper ; public class DB extends SQLiteOpenHelper { public static final String DATABASE_NAME = "Student.db" ; public static final String TABLE_NAME = "Student_Table" , COL_1 = "ID" , COL_2 = "NAME" , COL_3 = "SURENAME" , COL_4 = "MARKS" ; public DB(Context context) { super (context , DATABASE_NAME ,null, 1 ) ; SQLiteDatabase db=getWritableDatabase() ; } @Override public void onCreate (SQLiteDatabase db) { db.execSQL( "CREATE TABLE " + TABLE_NAME + " (ID INTEGER PRIMARY KEY AU...