doureng1083 2019-06-10 16:47
浏览 125

JSON的成功并未触发

I am having trouble with my JSON payload. The success function does not fire.

Thanks in advance for any help that can be provided. JLS

I get the value in the console so I know the query works okay but it is not in a key/value pair it just echos "VALUE" and does not triggers success.

//JS file ***UPDATED***

    $(document).ready(function(){
// code to get all records from table via select box
        $("#school").change(function() {
            var id = $(this).find(":selected").val();
            var dataString = 'school='+ id;
            $.ajax({
                url: 'cif_submit.php',
                dataType: "json",
                data: dataString,
                cache: false,
                success: function(data) {
                    if(data) {
                        alert(data);
                    }
                }
            });
        })
    });
//Here is the php  ***UPDATED***

if($_REQUEST['school']) {

$stmt = $conn->prepare("SELECT streetname FROM schoolinfo WHERE fullschoolname = :schoolname");
$stmt->execute (array(':schoolname' =>$_REQUEST['school']));

while($mydata = $stmt->fetch()) {   

    echo json_encode($mydata);  
} }
}

The JSON RESPONSE is:
{"streetname":"Colbeck Road, PO Bag 7200","0":"Colbeck Road, PO Bag 7200"}
  • 写回答

2条回答 默认 最新

  • doutun1362 2019-06-10 17:11
    关注

    I think changing the schooldata to data will fix the issue.

    评论

报告相同问题?

悬赏问题

  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 关于无人驾驶的航向角
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了