I am trying to perform a function that sends data in a php file with ajax
with the following code:
function buscar(){
var texto = $("#search").val();
var pagina = $("#pagina").val();
var datos_formulario = "texto="+texto+"&pagina="+pagina;
console.log(datos_formulario);
$.ajax({
type: 'POST',
url: 'http://localhost/prestamos-2017/backend/includes/buscar',
data: datos_formulario,
dataType: 'json',
beforeSend: function (objeto) {
},
success: function (json) {
console.log(json)
//$('.lista').html(json.registros);
//$(".btp").on("click", function(){
// $( "#tareaInput" ).focus();
//});
//tarea_completa(fecha_actual);
//color();
},
error: function (e) {
console.log('No se puede conectar al servidor');
},
complete: function (objeto, exito, error) {
}
});
}
But it gives an error in the console that says:
POST link 403 (Forbidden)
In my file routes.php
of codeigniter
I have the following line:
$route['backend/includes/buscar'] = 'includes/buscar';
Controller:
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class Buscar extends CI_Controller {
var $data;
var $current_user_id;
function __construct(){
parent::__construct();
$this->data->item_slug = 'motherform';
$this->data->text_item = 'formulario';
$this->data->text_items = 'formularios';
$this->data->text_gender = 'f';
}
function buscar() {
$this->load->view('backend/includes/buscar.php');
}
} ?>