0

I am using Jquery Ajax in Codeigniter, after register a user via bootstrap modal I got JSON data as below instead of fetching the data from table. Where I am wrong? please help!

{"success":true,"type":"add"}

Here is my Jquery function

```
<script>
$(function(){
    display();
    //add new

function display(){
    $.ajax({
        type:'ajax',
        url:'<?php echo base_url()?>frame_cont/display',

        async: false,
        dataType:'json',
        success:function(data){
            var html='';
            var i;
            for(i=0;i<data.length;i++){

                html +='<tr>'+
                            '<td>'+data[i].id+'</td>'+
                            '<td>'+data[i].username+'</td>'+
                            '<td>'+data[i].email+'</td>'+
                            '<td>'+data[i].password+'</td>'+
                            '<tr>';
            }
            $('#showdata').html(html);
        },
        error:function(){
            alert('Could not get Data from Database');
        }
});
};
});
</script>```

and here is controller class

<?php 
class Frame_cont extends CI_Controller{
    public function index(){
        $this->load->view('index');
    }

    public function register(){
        $this->load->model('frame');
        $result=$this->frame->insert();
        $msg['success']=false;
        $msg['type']='add';
        if($result){
            $msg['success']=true;
        }
        echo json_encode($msg);
        }




    public function display(){
        $this->load->model('frame');
        $result=$this->frame->display();
        echo json_encode($result);
    }
}

This is all about the code and sorry for the english

2 Answers 2

1

in your register function you doing echo json_encode($msg); at the end. you should echo inserted value inside if condition

Sign up to request clarification or add additional context in comments.

Comments

0

The issue occur because of I am using type="submit" instead of type="button" in my form button.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.