How to travel AJAX MVC?

0

I have problems when showing the message of the controller does not enter the function does not print the alert

HTML

<button type="submit" name="pdp_grafico" onclick="pdp_grafico();">PDP</button>

JS

<script src="js/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<script src="js/highstock.js"></script>
<script src="js/exporting.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/jquery.dataTables.min.js"></script>
<script>

    $(document).ready( function () 
    {
        $('#tabla').DataTable();
    });

    function pdp_grafico()
    {
        $.ajax({
            method:'GET',
            url:'controllers/HomeController.php/Prueba'
        }).done(function(data) 
        {
            alert(data);
        });
    }

</script>

CONTROLLER

<?php

require_once($_SERVER['DOCUMENT_ROOT']."/_class/DBConneccion.class.php");
require_once $_SERVER['DOCUMENT_ROOT'].'/_class/DB.php';

class HomeController extends DBConneccion 
{
    public function  __construct()
    {
        parent::__construct("chonchon");
    }

    function Prueba()
    {
        header('Content-type: application/json');  

        echo json_encode("Mensaje desde el controller"); 
    }
}
    
asked by Juan Perez 19.10.2018 в 14:01
source

1 answer

0

Try removing the onclick function, give the button an ID and try this:

<button type="submit" id="boton" name="pdp_grafico">PDP</button>

and the method would leave it like this:

   $("#boton").on('click',function(){

      $.ajax({

        url:"controllers/HomeController.php/Prueba",
        method:"GET",
        dataType:"Json",
        success:function(data){

        },
        error:function(data){
        alert("no se ha podido hacer");
        }   
     });
  });
})
    
answered by 29.11.2018 в 17:41