I have a problem, I make the connection to my action from the Javascript through AJAX and send the data by POST. I declare the URL "/ controller / action" and it does not connect to the action, and AJAX gives me "parsererror". The strange thing is that I did one the same but to receive of an equal action and it did not give me error and I worked well
My JS File
$.ajax({
url: '/user/save-account',
type: 'POST',
dataType: 'json',
data: {
'id_user': xxx,
'email': xxx,
'name': xxx,
'type': xxx
},
contentType: 'application/x-www-form-urlencoded;charset=ISO-8859-15',
async: false,
success: function (response) {
},
error : function (request, error) {
console.log(error);
}
});
My action in controller
public function actionSaveAccount(){
$model= new \frontend\models\ProfileForm();
if (Yii::$app->request->isAjax) {
if ($model->load(Yii::$app->request->post())){
if($profile === $model->saveProfile()){
// SAVED
}else{
// ERROR SAVED
}
}
}
}
My settings for URLs
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
],
],