How to return an Ajax response to my view from a controller in Zend Framework 1?

0

I tell you, I'm trying to return a data to my personal search, what I do is make an ajax call to the server, specifically to the action maintenance / validate registration, this data is shown in a console.log (response), just to test , but when the call returns to me instead of painting me the answer data paints me the html. Why is the answer not shown if I am using an echo in my php driver ?. I need help!
This is my Javascript code:

    $('#nrodoc').on('keyup', function(event){
        if($(this).attr('value').length == 8){
            $.ajax({
                url:jQuery.scriptPath+'index.php/mantenimientos/validarregistro',
                data: {dni: $('#nrodoc').attr('value')},
                type: 'POST',
                success: function(response){ 
                    $('#nrodoc').val('')
                    console.log(response);
                    openDialogWarning('El dni no es valido! ', 380, 150);                       
                },
                error: function(xhr, status, error){
                    console.log('Disculpe, ocurrió un problema, Error: '+ error + ', Estado: ' +xhr.status)
                },
                complete: function(xhr, status){
                    console.log('Petición realizada')
                }
            });
        } 
    });  

and my PHP code is:

public function validarregistroAction() {
$this->_helper->layout->disableLayout();
$this->_helper->getHelper('ajaxContext')->initContext();
if ($this->getRequest()->isXmlHttpRequest()) {
        $url = $this->view->util()->getPath();
        if(($this->_getParam('dni'))!=null){
            $this->_redirect($url.'index.php/registro');
            $dni = $this->_getParam('dni');
            $this->_helper->viewRenderer->setNoRender();
            echo "Hello";
        }
}
}
    
asked by Luis De La Peña 09.03.2018 в 21:09
source

0 answers