【发布时间】:2018-11-12 06:45:48
【问题描述】:
通过php从mysql获取数据以响应本机时,json解析错误中无法识别的令牌<没有得到任何解决方案
本机代码:
login = () => {
alert("go you");
fetch('http://192.168.1.104/testmt.php',{
method:'POST',
headers:{
'Accept':'application/json',
'Content-Type':'text/json'
},
body:JSON.stringify({
namee:'teja'
})
})
.then((response) => response.json())
.then((responseJson) => {
alert(JSON.stringify(responseJson));
}).catch((error) => {
console.error(error);
})
}
php代码:
<?php
$link = mysql_connect('localhost','root','','trial');
if (!$link) {
echo json_encode('not done');
}
echo ('hello');
?>
【问题讨论】:
-
如果你自己运行 PHP 会发生什么?听起来它要么没有被执行,要么正在抛出错误。请记住,
mysql_*函数在较新的版本中根本不存在。