Click here to Skip to main content
15,886,778 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

How can I display a data from database in codeigniter using Ajax? I'm looking for sample codes but I cant find some reference.

JavaScript
$.ajax({
            
            type: "POST",
            url: "mainController/testForAjax",
            data: $("#searchInput").val(),
            success: function(){
                
                console.log('Test result message of ajax')
            }
        });


I have this code, basically I want to call the mainController's testForAjax method. That method calls a database, and then sends it back to testForAjax to do print_r().
Posted
Updated 16-Feb-17 1:37am
Comments
Sunasara Imdadhusen 9-May-14 0:14am    
So using this code what is your problem
KatsuneShinsengumi 9-May-14 0:32am    
I dont know how to test if it's working or not because it's still refreshing the whole page.

1 solution

I got it now

JavaScript
$('form.ajaxForm').on('submit',function() {
                $.ajax({
                        type: 'POST',
                        url: 'YOUR LOCAL HOST HERE OR BASE URL/maincontroller/testForAjax',
                        data:{ search: $("#searchInput").val(), searchType: $("#searchTypeID").val() },
                        dataType: 'JSON',
                        success: function(smg) {
                                
                        }
                });
        });
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900