Ajax (Angularjs) returning HTML from the page itself

Asked

Viewed 31 times

0

I am using Codeigniter to retrieve the database data.

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");
    });
});

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

  • You did not identify your problem? has how to inform?

  • My problem is that in json_encode, it is returning me, in addition to json, several Htmls tags. https://uploaddeimagens.com.br/imagens/capturr-png-7c61bffc-f9fa-4a0c-a0e8-772cfd4bc8e7

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.