Ajax (AngularJS) returning HTML from the page itself

0

I am using Codeigniter to retrieve data from the database.

Controller:

  <?php
    defined('BASEPATH') OR exit('No direct script access allowed');
    class Welcome extends CI_Controller {
        public function __construct() {
            parent::__construct();
            $this->load->database();
            $dados = array(
                "url" => base_url()
            );
            $this->parser->parse('layout', $dados);
        }
        public function index(){        
        }
        public function getbanda() {
            echo json_encode($this->Crud->select('banda'));

        }
    }

Model:

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Crud extends CI_Model {
    public function select($table){
        $this->db->from($table);
        $dados = $this->db->get();
        return $dados->result_array();
    }
}

Ajax:

var app = angular.module("MyApp", []);
app.controller("MyCtrl", function ($scope, $http) {
    var banda = {};
    $scope.band = banda;
    $http({
        method: 'GET',
        url: 'index.php/Welcome/getbanda/'
    }).then(function success(response){
        $scope.band = response.data;
        console.log($scope.band);
    },function error(response){
        alert("Error");
    });
});

The echo is returning an HTML from the page itself. How to solve?

    
asked by anonymous 19.03.2018 / 00:02

0 answers