0
我想将我的变量javascript发布到php文件。 我不能发布变量,但能够传递json数据。将变量从JavaScript传递到php(通过获取api)
我的代码是这样的。
var check = 'hello';
var check1 = 'hello1';
fetch('http://localhost/react_task/react-webpack-boilerplate/php/api.php', {
method: 'post',
body: JSON.stringify({
a: 2, // here passing variable doesn't work
b: 1 // like check and check1 does't show any values while passing here
})
}) .then(function(response) {
if (response.status >= 200 && response.status < 300) {
return response.text()
}
throw new Error(response.statusText)
})
.then(function(response) {
console.log(response);
})
你可以请指导我,如何将变量从JavaScript传递到PHP。
我与工作发生反应,JS和文件类型JSX工作..所以它很难使用JSX文件格式 –
阿贾克斯,我只希望使用取... –