首页 > Resource interpreted as Document but tran..

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代码:
<?php
error_reporting(0);
header("Content-type:application/json;charset=utf-8;");
//测试数据连接
$icon=mysql_connect("localhost","root","");
if(!$icon){

//失败
die('Could not connect:'.mysql_error());

}
//连接数据库
mysql_select_db("news_data",$icon);
//设置中文
mysql_query("set names utf8");
//获取前台type,data参数
$type=@$_GET['type'];
$sleword=@$_GET['data'];
switch ($type) {

//从主页前段到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($wordArray);$i++){//php数组没有length,获取数组长度要用count函数?
             if($wordArray[i].new_class==$sleword){
                 //这里传值$wordArray[i].new_class的值给js
                 //...    
                 echo json_encode ($wordArray[i]['new_class']);
             }
         }
    break;
//从后台前端网页插入数据到php
case insertdata:
    $sql="INSERT INTO info_look (new_title,new_class) values ('$_POST[new_title_info]','$_POST[new_class_info]')";
    if(!mysql_query($sql,$icon)){
        die('Error:' . mysql_error());
    }
    echo "one title added!";
    break;

}
mysql_close($icon);
?>


问题出在最后一句,前段期望返回的是'json',虽然你在pho头部设置了header,但是你看这句

'''Php

echo "one title added!";

'''

【热门文章】
【热门文章】