Answer the question
In order to leave comments, you need to log in
Vk mini app on react. How to generate json response on php side?
Greetings.
I decided to deal with the creation of applications on VK MiniApps and got stuck on the obvious.
Required by making a request to the php script from the application. Get data from it in json for further work with them.
We have a php script for the test:
<?php
header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept');
header('Access-Control-Allow-Methods: POST,GET,OPTIONS');
$json = array(
'site_url' => array(
'URL' => 1234,
),
);
header('Content-Type: application/json; charset=utf-8');
echo json_encode($json);
?>
{"site_url":{"URL":1234}}
axios
.get("https://site.pw/app/zx.php")
.then((response) => {
console.log(response.data);
})
.catch((error) => {
console.log(error);
});
}
Error: Network Error
at createError (https://oe8vd.csb.app/node_modules/axios/lib/core/createError.js:16:15)
at XMLHttpRequest.handleError (https://oe8vd.csb.app/node_modules/axios/lib/adapters/xhr.js:91:14)
Answer the question
In order to leave comments, you need to log in
The reason was found. But I did not understand how to solve it. The problem turned out to be due to cloudflare. They change the header or keep it in the cache. I cleared the cache, but it didn't help. Also tried Development mode. But it didn't help either. Everything works on the server without cloudflare proxying. In which direction to dig further I do not know.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question