The ajax request not detected in the AppController.
I have printed the params array. Here is the sample.
CakeRequest Object ( [params] => Array ( [plugin] => [controller] => permissions [action] => api_auth [named] => Array ( ) [pass] => Array ( ) [prefix] => api [api] => 1 [ext] => json [_Token] => Array ( [key] => 00f665112046ea0d5794b5f93b6a035f62a59ada [unlockedFields] => Array ( ) ) [isAjax] => ) [data] => Array ( ) [query] => Array ( ) [url] => api/permissions/auth.json [base] => [webroot] => / [here] => /api/permissions/auth.json [_detectors:protected] => Array ( [get] => Array ( [env] => REQUEST_METHOD [value] => GET ) [post] => Array ( [env] => REQUEST_METHOD [value] => POST ) [put] => Array ( [env] => REQUEST_METHOD [value] => PUT ) [delete] => Array ( [env] => REQUEST_METHOD [value] => DELETE ) [head] => Array ( [env] => REQUEST_METHOD [value] => HEAD ) [options] => Array ( [env] => REQUEST_METHOD [value] => OPTIONS ) [ssl] => Array ( [env] => HTTPS [value] => 1 ) [ajax] => Array ( [env] => HTTP_X_REQUESTED_WITH [value] => XMLHttpRequest ) [flash] => Array ( [env] => HTTP_USER_AGENT [pattern] => /^(Shockwave|Adobe) Flash/ ) [mobile] => Array ( [env] => HTTP_USER_AGENT [options] => Array ( [0] => Android [1] => AvantGo [2] => BlackBerry [3] => DoCoMo [4] => Fennec [5] => iPod [6] => iPhone [7] => iPad [8] => J2ME [9] => MIDP [10] => NetFront [11] => Nokia [12] => Opera Mini [13] => Opera Mobi [14] => PalmOS [15] => PalmSource [16] => portalmmm [17] => Plucker [18] => ReqwirelessWeb [19] => SonyEricsson [20] => Symbian [21] => UP\.Browser [22] => webOS [23] => Windows CE [24] => Windows Phone OS [25] => Xiino ) ) [requested] => Array ( [param] => requested [value] => 1 ) ) [_input:protected] => )
This is how I have checked the ajax request..
if($this->request->is('ajax')){
//ajax request
} else {
// not ajax request.
}
But always I get false result i.g not ajax request.
I am using the cakephp 2.3 version.
Here is the code sample of the ajax request code.
$.ajax({
url: backendAPI +'/students/profile.json',
type: 'POST',
data: this.studentdata,
dataType: 'json',
context: this
})
.done(function(response, textStatus, XMLHttpRequest) {
if( response.students.status == 'success' ) {
self.model.fetch();
mStitute.moduleTRANS['LeftSideBarStudent'].fetch();
} else {
if( response.students.message_type == 'single' ) {
Core.showAlert(response.students.message.toString(), 'show', response.students.status);
Core.hideAlert(10000);
} else {
var message = "";
$.each(response.students.message, function(i, v){
message = message + '<br/>' + v;
});
Core.showAlert(message, 'show', response.students.status);
Core.hideAlert(10000);
}
}
});
Router::parseExtensions('json');
enabled? – Roberto Maldonado