Failed to send Javascript data to action by POST method...

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


        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) {




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


                    // 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>',



I think the problem is

if($profile === $model->saveProfile()){

You didn’t set $profile so yii respond with a notice error which cause the ajax error on client side.

When dealing with ajax is useful to use tool liker the developers tools built-in in chrome and firefox or extension like firebug so you can easily analyze the ajax communication.

you are getting parse error because you are probably not returning json, double check if your response is json encoded.

Yes is JSON encoded

The problem is that it does not perform anything in the action, but when the redirect does not execute the action

What do you mean exactly?

If you put a


as first row of the action do you see it as answer to you ajax?

if you disable the ajax check in the action and call the url directly from the browser do you get anything?