1

This is my script:

$.post('index.php?r=site/filterbyprice',{
        price_range:values,
        _csrf : $("#csrftoken").val()
        }
        ,function(r){
            console.log(r);
            if(r==""){
                $("#all-ads").html('<div class="error-page"></div>');
            }
            else{
                $("#all-ads").html(r);  
            }
    });

controller code:

public function actioAbc(){
    echo 'inside abc';
}

I am facing the following error: Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://mandigoods.com/frontend/web/index.php?r=site/abc. (Reason: CORS header 'Access-Control-

Community
  • 1
  • 1

1 Answers1

0

Could be a header config problem. First, try to generate your url with:

$url = yii\helpers\Url::to(['site/filterbyprice']);

and including it into your view like this:

$this->registerJs(<<<JS

$.post('{$url}',{...});

JS;
);

excluding the _csrf : $("#csrftoken").val() that should be handled by Yii2 automatically.

Then, I'd check your server config (Apache / Nginx) regarding your headers, check this answer for the configuration.

Community
  • 1
  • 1
edoardo849
  • 103
  • 4