我正在尝试将数据从我的react原生应用程序发送到用PHP编写的远程应用程序服务器,以下是它的代码片段:
fetch('http://172.20.10.2/fyp/products.php', {
method: 'POST',
body: JSON.stringify({
//passing input data to server
cid: this.state.category_id
})下面是我尝试从react原生应用程序接收数据的PHP代码:
// Getting the received JSON into $json variable.
$json = file_get_contents('php://input');
// decoding the received JSON and store into $obj variable.
$obj = json_decode($json,true);
$obj_id = $obj['cid'];为了进行调试,我将$obj_id打印到.txt文件,但它没有打印任何内容,这表明我没有在服务器中接收到数据。我该如何解决这个问题?
发布于 2018-05-04 03:45:33
在php文件的最顶端添加
header("Access-Control-Allow-Origin:*");header("Access-Control-Allow-Headers:*");
然后重试!
https://stackoverflow.com/questions/50147904
复制相似问题