Javascript JSON.parse意外的数据结束错误

Javascript JSON.parse意外的数据结束错误,javascript,php,jquery,mysql,json,Javascript,Php,Jquery,Mysql,Json,我正在尝试使用php和jQueryAjax从mysql数据库加载数据,以填充下拉列表。但我在firefox和chrome中不断出现错误。firefox中的错误是JSON.parse意外数据结束,而chrome中的错误是语法错误意外输入结束。我检查了chrome中的网络选项卡,但没有响应数据。请告知。多谢各位 elihu.js $(document).ready(function(){ $.ajax({ type: "POST",

我正在尝试使用php和jQueryAjax从mysql数据库加载数据,以填充下拉列表。但我在firefox和chrome中不断出现错误。firefox中的错误是JSON.parse意外数据结束,而chrome中的错误是语法错误意外输入结束。我检查了chrome中的网络选项卡,但没有响应数据。请告知。多谢各位

elihu.js

$(document).ready(function(){   
    $.ajax({            
        type: "POST",
        contentType:"application/json",         
        dataType:"json",                        
        url:"http://localhost/josiejay/states.php",
        success: function(data) { 
            $("#personalstate").append("<option value='" + data.state_code + "'>" + data.state + "</option>");
        },
        error: function(xhr, status, error) {
            alert("Error: " + xhr.status + " - " + error);
        }
    }); 
}); 
$(文档).ready(函数(){
$.ajax({
类型:“POST”,
contentType:“应用程序/json”,
数据类型:“json”,
url:“http://localhost/josiejay/states.php",
成功:函数(数据){
$(“#personalstate”).append(“+data.state+”);
},
错误:函数(xhr、状态、错误){
警报(“错误:+xhr.status+”-“+Error”);
}
}); 
}); 
states.php

<?php


require('database.php');

function getStates() {
    global $db;
    $query = 'SELECT * FROM states';

    try {
        $statement = $db->prepare($query);
        $statement->execute();
        $states = $statement->fetchall();
        $statement->closeCursor(); 

        $json_data = json_encode($states); 
        echo $json_data;
    } catch (PDOException $e) {
        $error_message = $e->getMessage();
        exit();
    }
}
?>


$(“#personalstate”).append(“data.state+”)这就是问题所在。我将代码更改为$(“#personalstate”).append(“+data.state+”);但我仍然收到相同的错误。您之前仍然缺少报价”“。我认为您需要检查浏览器开发人员控制台中的响应数据,并确保它是有效的JSON。开发人员控制台中没有响应数据。@user3413326请尝试以下操作
success:function(data){console.log(data)}