Maison > Article > développement back-end > javascript - Resource interpreted as Document but tran..
问题如题,我测试数据的时候,浏览器跳出Resource interpreted as Document but transferred with MIME type application/json: "http://localhost:82/js4-1.php?type=findnew&data=pic".的提示,是json数据类型错误了吗?
php代码:
error_reporting(0);
header("Content-type:application/json;charset=utf-8;");
//测试数据连接
$icon=mysql_connect("localhost","root","");
if(!$icon){
<code>//失败 die('Could not connect:'.mysql_error());</code>
}
//连接数据库
mysql_select_db("news_data",$icon);
//设置中文
mysql_query("set names utf8");
//获取前台type,data参数
$type=@$_GET['type'];
$sleword=@$_GET['data'];
switch ($type) {
<code>//从主页前段到php case 'findnew': $sql="select id,new_title,new_class from info_look";//创建查询语句 $re=mysql_query($sql);//执行语句 $wordArray=[];//创建空字符串承载获取到的数据 while($row=mysql_fetch_array($re)){ $wordArray[]=$row;//将结果赋值给数组 } //下面打算用循环找到对应传递过来的data参数,匹配到了,就把他回传给前台 for($i=0;$i<count if echo json_encode break case insertdata: into info_look values die . mysql_error title added></count></code>
}
mysql_close($icon);
?>
问题如题,我测试数据的时候,浏览器跳出Resource interpreted as Document but transferred with MIME type application/json: "http://localhost:82/js4-1.php?type=findnew&data=pic".的提示,是json数据类型错误了吗?
php代码:
error_reporting(0);
header("Content-type:application/json;charset=utf-8;");
//测试数据连接
$icon=mysql_connect("localhost","root","");
if(!$icon){
<code>//失败 die('Could not connect:'.mysql_error());</code>
}
//连接数据库
mysql_select_db("news_data",$icon);
//设置中文
mysql_query("set names utf8");
//获取前台type,data参数
$type=@$_GET['type'];
$sleword=@$_GET['data'];
switch ($type) {
<code>//从主页前段到php case 'findnew': $sql="select id,new_title,new_class from info_look";//创建查询语句 $re=mysql_query($sql);//执行语句 $wordArray=[];//创建空字符串承载获取到的数据 while($row=mysql_fetch_array($re)){ $wordArray[]=$row;//将结果赋值给数组 } //下面打算用循环找到对应传递过来的data参数,匹配到了,就把他回传给前台 for($i=0;$i<count if echo json_encode break case insertdata: into info_look values die . mysql_error title added></count></code>
}
mysql_close($icon);
?>
问题出在最后一句,前段期望返回的是'json',虽然你在pho头部设置了header,但是你看这句
'''Php
<code>echo "one title added!";</code>
'''