简体   繁体   中英

retrieve mysql data using jquery and php

I have tried this and works fine on my localhost but on the server 000webhost.com it does not work. Also the Jquery does not work in IE but the other browsers. it is IE 10

What I would like to do is have the the user select a province from a <select> and then based on the province selected the cities for that province must be loaded into another <select>

here is the relevant jquery:

where '#searchProvince' and '#searchCity' are the two <select>

var province = "";
    $("#searchProvince").on("change",function(){
        province = $("#searchProvince").val();


        //Retrieve all cities under the province
        $.post("phpScripts/get_cities.php",{province: province}, function(output){
            results = $.parseJSON(output);

            $("#searchCity").empty();

            $("#searchCity").append("<option value=\"" +results[0]+ "\" selected=\"selected\">"+results[0]+"</option>");

            for(i = 1; i < $(results).length; i++)
            {
                    $("#searchCity").append("<option value=\"" +results[i]+ "\">"+results[i]+"</option>");
            }
        });
    });

}); 

then when this is passed to the php page get_cities.php

<?php
    $city = array();
    if(isset($_POST['province']) === true && empty($_POST['province']) === false)
    {
        $province = $_POST["province"];
        require "connect.php";

        $query = mysqli_query($con,"SELECT DISTINCT city FROM _tblGeo WHERE province = '".$province."'");

        $i = 0;
        while ($row = mysqli_fetch_row($query))
            {
                $city[$i] = $row[0];

                $i++;
            }

    }
    echo json_encode($city);
?>

Per the asker's request:

I have tested it on freemyslq hosting and found that the problem was my SQL query the data is only is "small" letters hence _tblGeo should have been "_tblgeo".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM