php – Post parameters in yii via ajax


calling ajax in my script using jquery. To do this, I created a separate controller (AjaxController) and in it a certain actionRequest method. jQuery passes the post request there:

    url: location.origin + '/ajax/request',
    async: false,
    type: 'POST',
    data: {'params': params},//масив
    dataType: 'json',
    success: function(data) {result = data}

in the script itself, there is already the following code:

$params = Yii::$app->request->get('params')
echo $params;

The problem is that post-requests do not want to reach the server. get goes fine, but I change to post – nothing comes. Moreover, I make a request to my script (just a php script not tied to the engine)) – everything is going fine …

ps I do not know yet how to interpret all this. I put the following actions in the action code:

$file = fopen($root . '/text.txt', 'w');
fwrite($file, '1');

If I send a get-request, then the file is created in the root of the site. if I pass post, then even the file does not want to be created. It seems that it breaks off somewhere much earlier and even my code does not execute when sending a post request …



$id = Yii::app()->request->getPost('id');     // Только post
$id = Yii::app()->request->getParam('id');    // Для post и get
Scroll to Top