javascript - Resource interpreted as Document but tran..

WBOY
Release: 2016-08-08 09:06:35
Original
1929 people have browsed it

The question is as mentioned. When I tested the data, the browser popped up the prompt Resource interpreted as Document but transferred with MIME type application/json: "http://localhost:82/js4-1.php?type=findnew&data=pic". ,is the json data type wrong?

javascript - Resource interpreted as Document but tran..

php code:
error_reporting(0);
header("Content-type:application/json;charset=utf-8;");
//Test data connection
$icon=mysql_connect("localhost ","root","");
if(!$icon){

<code>//失败
die('Could not connect:'.mysql_error());</code>
Copy after login
Copy after login

}
//Connect to the database
mysql_select_db("news_data",$icon);
//Set Chinese
mysql_query("set names utf8");
//Get the front-end type, data parameters
$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($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;</code>
Copy after login
Copy after login

}
mysql_close($icon);
?>

Reply content:

The question is as mentioned. When I tested the data, the browser popped up the prompt Resource interpreted as Document but transferred with MIME type application/json: "http://localhost:82/js4-1.php?type=findnew&data=pic". ,is the json data type wrong?

javascript - Resource interpreted as Document but tran..

php code:
error_reporting(0);
header("Content-type:application/json;charset=utf-8;");
//Test data connection
$icon=mysql_connect("localhost ","root","");
if(!$icon){

<code>//失败
die('Could not connect:'.mysql_error());</code>
Copy after login
Copy after login

}
//Connect to the database
mysql_select_db("news_data",$icon);
//Set Chinese
mysql_query("set names utf8");
//Get the front-end type, data parameters
$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($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;</code>
Copy after login
Copy after login

}
mysql_close($icon);
?>

The problem lies in the last sentence. The previous paragraph expects to return 'json'. Although you set the header in the pho header, you can see this sentence

''Php

<code>echo "one title added!";</code>
Copy after login

'''

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!