Welcome Guest, Not a member yet? Register   Sign In
Data controller
#1

Hi
I'm having an issue with getting data from Controller, I have tried all the solutions here but it's the same..

when I click on the button it says 404 not found, if I change the URL to completed URL included the controller class name + function name, it says 403

Here is my view code :

<h2>Quiz</h2>
<script type="text/javascript">
$(document).ready(function(){
    var BASE_URL = '<?php echo base_url(); ?>';
    $('#show').click(function(e){
        console.log(BASE_URL);
        $.ajax({
            url: BASE_URL + "Quiz/get_item",
            dataType:'text',
            type:"POST",
            success: function(result){
                var obj = $.parseJSON(result);
                console.log(obj);
            }
        })
    })
});
</script>

<button id="show">Show Cutomers</button>

<div id="customers-list"></div>

<p>Our first multi-page CodeIgniter application! Each page has its own controller and vie

Here is my Controller code :

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Quiz extends CI_Controller {

  var $TPL;

  public function __construct()
  {
    parent::__construct();
      $this->load->model('Quiz_data');
    // Your own constructor code
  }
  function show_customers()
    {
    $query = $this->db-> query("SELECT * FROM quiz ORDER BY id;");
    $this->TPL['listing'] = $query->result_array();

    $this->template->show('quiz', $this->TPL);
    }

  public function index()
  {
    $this->template->show('quiz', $this->TPL);
  }
  public function get_item(){
        $data = $this ->Quiz_data->get_data();
        echo json_encode($data);
    }
}

Here is my Model code :

<?php

class Quiz_data extends CI_Model {

        public function get_data()
        {     
                $query = $this->db->get('quiz');
                return $query -> result_array();
        }
}
Reply




Theme © iAndrew 2016 - Forum software by © MyBB