Is it possible to emulate a valid AJAX request?

axios.post('php/data.php', { act: 'load' }) .then(function (response) { console.log(response); }) .catch(function (error) { console.log(error); }); 

data can be obtained through

 $array = json_decode(file_get_contents('php://input'), true); 

I want to get data in $ _POST

  • It is not entirely clear what the question is: use other sugar? - Tachkin
  • Duck is not sugar but a default as for me - des1roer

1 answer 1

import axios from 'axios';

  axios.defaults.xsrfHeaderName = "X-CSRFTOKEN"; axios.defaults.xsrfCookieName = "XCSRF-TOKEN"; 

On the receiving server you need to put the setting:

  CSRF_COOKIE_NAME = "XCSRF-TOKEN" 
  • axios.defaults.headers.common = {'X-Requested-With': 'XMLHttpRequest'}; - des1roer
  • about the server did not understand - des1roer
  • Do you have a Backend Server that distributes REST data? On this server it is possible to configure CSRF_COOKIE_NAME. This setting must be set to "XCSRF-TOKEN" - yestema
  • for yii2 where to do it then? - des1roer