Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/366.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 未捕获的语法错误:意外标记<;在JSON.parse(<;匿名>;)的位置0处的JSON中_Javascript_Php_Jquery_Arrays_Json - Fatal编程技术网

Javascript 未捕获的语法错误:意外标记<;在JSON.parse(<;匿名>;)的位置0处的JSON中

Javascript 未捕获的语法错误:意外标记<;在JSON.parse(<;匿名>;)的位置0处的JSON中,javascript,php,jquery,arrays,json,Javascript,Php,Jquery,Arrays,Json,我想将一个数组从PHP文件传递到JavaScript,并存储在JavaScript数组中。下面是JavaScript代码: xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange=function(){ if (xmlhttp.readyState==4 && xmlhttp.status==200) {

我想将一个数组从PHP文件传递到JavaScript,并存储在JavaScript数组中。下面是JavaScript代码:

xmlhttp = new XMLHttpRequest();
            xmlhttp.onreadystatechange=function(){
             if (xmlhttp.readyState==4 && xmlhttp.status==200)
             {
                    nameData = JSON.parse(xmlhttp.responseText); 
                    console.log(xmlhttp.responseText);
                }
            }
            xmlhttp.readyState=4;
            xmlhttp.open("GET","mapPHPname.php?Zip="+zipcode,true);
            xmlhttp.send();
PHP文件:

<?php
$zip=isset($_GET['Zip']);
include 'dbconnect.php';
$sql="Select `name` from doctor where `zip` LIKE $zip";
$result = mysql_query( $sql, $conn );
$num_rows = mysql_num_rows($result);
array(name);
if($num_rows>=1)
{
    $count=0;
    while($res_array = mysql_fetch_assoc($result))
    {
        $name[$count]=$res_array['name'];
    }
}
else
{
    $name[0]="kashyap"; 
}
echo json_encode($name);
?>

我得到这个错误:

未捕获的SyntaxError:JSON中位置0处的意外标记< 在JSON.parse(


1-您不能这样声明数组:
array(name)

请改为尝试:
$name=array()
$name=[]

2-引用include
include'dbconnect.php'

3-正确访问变量
count
,位于
$name[count]=$res_数组['name']
count
应该是
$count


而实际上你并不是在循环它。在保存到
$name
数组后,您应该设置
$count++

responseText()中到底是什么?你试过console.log()吗?我猜你从服务器上得到了一些HTML或XML。如果有
,这是一个SQL注入的教科书示例。您可以通过调整URL中的
Zip
参数来编写自定义SQL。