Skip to content Skip to sidebar Skip to footer

Ajax Not Calling Success Function

I'm using ajax to validate a from without reloadind the page. Script Ajax function updateResult(tab){ $.ajax({ url:'requeteSpecimen.php',

Solution 1:

You do not call actions like that in Cakephp.

First set up an Action in one of your Controllers call the url from your $.ajax function like this.

functionupdateResult(tab){
        $.ajax({
            url:"/controller/request_specimen",
            data:{datas:tab},
            dataType: 'text',
            async:false,
            success: function(data){
                document.getElementById('resultat').innerHTML = '<p>'+data+'</p>';
            },
            error: function(data){
                document.getElementById('resultat').innerHTML = '<p>ERROR</p>';
            }
        });
}

You could later on add a route for request_specimen and make it prettier.

In your Controller there should be a method called: public function request_specimen() {} Wich will handle the ajax request like so: if($this->request->is(['ajax']) { /* Handle request */}

The data sent to the function will be in $this->request->data;

Post a Comment for "Ajax Not Calling Success Function"