Sample AJAX Call and Response

23666This is just a quick example of how to send a reply from your controller to n AJAX request.

//you controller

public function testajax(){
  $this->set('text', 'its a SUCCESS');
  $this->set('_serialize', ['text']);
}

//javascript function

<script>	
	function test(){
		$.ajax({
			type:"POST",
			url:"http://localhost/[YOURCAKEAPPNAME]/[CONTROLLERNAME]/testajax.json",
			async:true,
			success: function(response){
				//console.log('success');
				console.log(response.text);
			},
			error: function (response) {
				console.log('error');
				console.log(response.text);
			}
		});			
    }
</script>

A link to call the function;

<li><?= $this->Html->link(__('updateResult'), 'javascript:test()') ?></li>