S
S
SPART4K2021-08-12 09:36:20
PHP
SPART4K, 2021-08-12 09:36:20

Why is the php file not working in vue/nuxt?

Good afternoon.
In my project, I need to change my local json file, I have it in the static / data.json folder.
There is also a php file in the static folder of this type:

<?php
  $data = $_POST['data'];

  fopen('data.json', 'w+');
  // fwrite($file, $data);
  file_put_contents('data.json', null);
  fclose('data.json');
  print('xyu');
?>


And my post request:
sendJson() {
        axios.post('test.php', this.DATAMAIN )
        .then(function (response) {
          console.log(response);
        })
        .catch(function (error) {
          console.log(error);
        });
      }


I want to first at least clear it, in the console it displays that the request has been sent, but nothing happens to the file.
Please tell me what is the problem

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Yarkov, 2021-08-12
@yarkov Vue.js

Please tell me what is the problem

Completely incomprehensible about what you are doing. Should the PHP file be launched by magic or by the interpreter? So why PHP if you have Node.js?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question