Heim  >  Artikel  >  Backend-Entwicklung  >  javascript - Resource interpreted as Document but tran..

javascript - Resource interpreted as Document but tran..

WBOY
WBOYOriginal
2016-08-08 09:06:351894Durchsuche

问题如题,我测试数据的时候,浏览器跳出Resource interpreted as Document but transferred with MIME type application/json: "http://localhost:82/js4-1.php?type=findnew&data=pic".的提示,是json数据类型错误了吗?

javascript - Resource interpreted as Document but tran..

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数据类型错误了吗?

javascript - Resource interpreted as Document but tran..

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>

'''

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn