Error 500 In Renderpartial (On Ajax)

Hello to everyone, i’m having a big problem with the AJAX and yii2, when i make a ajax petition to my controller (who returns a renderPartial) it returns the content correctly (without any error) but the http header is (500 Internal Server Error)

Cause of this, jQuery thows the “failure” statement and i can’t receive the data of the ajax

My Controller Action code (PHP)

public function actionRenoveSubscription() {

        header("Access-Control-Allow-Origin: *");

        return $this->renderPartial('subscriptionRenove');


Also i tried with the print statement like this

public function actionRenoveSubscription() {

        header("Access-Control-Allow-Origin: *");

        print $this->renderPartial('subscriptionRenove');


And here is my Js (AJAX) code

    jQuery("#renovate").click(function() {

        jQuery.ajax("<?= Yii::getAlias("@web"); ?>/?r=user-subscription/renove-subscription")

                .done(function(data) {



                .fail(function(mp, mp2, data) {

                    alert("Ha ocurrido un error técnico, \nEl equipo técnico está avisado");



I’m always recive this error (ISE 500)

But the server returns me the content ‘asd’ in this case (testing) sorry but i can’t attach any image (Cause i’m new on the forum)

Any help? thank’s you very much

I have the same problem. Please, help us :-[

why you are writing this

header("Access-Control-Allow-Origin: *");

in your controller?

You can use

return $this->renderAjax('subscriptionRenove');

I’ve tried that but i still having the same problem.

This is my code

if ($model->save())

            return $this->renderAjax("renderAjax",["result"=>"ok"]);


            return $this->renderAjax("renderAjax",["result"=>"ko"]);

and renderAjax view:

echo json_encode(array("result"=>$result));

It seems curious, but when there are too many results, like 20, then, the 500 error disappear. :blink: