javascript - Resource interpreted as Document but tran..
PHP中文网
PHP中文网 2017-04-11 12:00:14
[JavaScript讨论组]

问题如题,我测试数据的时候,浏览器跳出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);
?>

PHP中文网
PHP中文网

认证高级PHP讲师

全部回复(1)
天蓬老师

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

'''Php

echo "one title added!";

'''

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号