没有使用codeingiter api获取数据,使用react js浏览器构建获取方法



我用Codeigniter创建了一个API,我用postman测试了它,它在那里工作得很好,但是当我用react js击中它时,post数据没有出现在服务器端

下面是react代码

async function submitForm() {
const response = await fetch(
"url",
{
method: "POST", // *GET, POST, PUT, DELETE, etc.
body: JSON.stringify({
first_name: enteredFirstName,
last_name: enteredLastName,
email: enteredEmail,
company_name: enteredComapanyName,
phone: enteredPhone,
company_type: cType,
}), // body data type must match "Content-Type" header
}
);
console.log(response.json());
}

这里是服务器端Codeigniter代码

头("Access-Control-Allow-Origin: *");print_r ($ _POST);

我正在从客户端传递值,但没有在服务器端获得它

我得到一个空数组

我正在等待从客户端传递的数据数组我尝试了几乎所有的头,但没有得到任何数据我认为这可能是一个标题问题,因为我在firebase

中获取数据

问题是我用JSON传递数据并在服务器端获取数据是表单数据这就是为什么它是一个空数组

这是获取json数据的方式

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

最新更新