I am using $.ajax for the first time in CakePhp2.4.5- I read a lot of Posts on stackoverflow and did other research on w3schools and jquery site but could not understand how should I solve my problem. I want to send data to the Controller from my 1st view index.ctp
$.ajax({
type: 'POST',
url: 'meers/client',
datatype:'json',
cache: false,
data: {myVal:'Success!'},
success: function(){alert('AjaX Success')},
error: function(){alert('AjaX Failed')}
})
.done(function(){
alert('AjaX Done!');
});
alert show 'AjaX Success'.
in my Controller I have
public function client(){
if($this->request->isAjax()){
$this->set('ajaxTest','Success');
}}
in my SECOND view client.ctp I have.
if(isset($ajaxTest)){
echo $ajaxTest;
}else{
echo 'ajaxTest not Set.';
}
PROBLEM. I always get msg in my Client.ctp view "ajaxTest not Set". What am I doing wrong ? or How to Do it ? Thanks
is('ajax')instead of theisAjax? It seems the second syntax is deprecated. Please note that JavaScript is case-sensitive, thedatatypeproperty should bedataType.'ajaxTest not Set.'for non-ajax request or you debug the request in the browser's console?