亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

都道府県情報(bào)を自動(dòng)的にロードする

#jquery ファイルの紹介:

##<script src="./jquery-1.11.0.js" type="text/javascript " ></script>


##region.html にコードを追加します:

$(document).ready(function() {} ページの読み込みを通じて Ajax リクエストを送信します

<script type="text/javascript">
    $(document).ready(function() {
        //  加載所有的省份
        $.ajax({
            type: "get",
            url: "region_action.php", // type=1表示查詢省份
            data: {"parent_id": "1", "type": "1"},
            dataType: "json",
            success: function(data) {
                $("#provinces").html("<option value=''>請選擇省份</option>");
                $.each(data, function(i, item) {
                    // alert(item.region_id);
                    $("#provinces").append("<option value='" + item.region_id + "'>" + item.region_name + "</option>");
                });
            }
        });
</script>

新しいregion_action.phpファイルを?qū)g行します。すべての州の値、つまり、region_type=1、parent_id=1を取得するためのデータベース クエリ

##コードは次のとおりです:

<?php
header("Content-Type:text/html;charset=utf-8");
include './mysqli.php';
$type = isset($_GET["type"]) ? $_GET["type"] : "";
$parent_id = isset($_GET["parent_id"]) ? $_GET["parent_id"] : "";
// 鏈接數(shù)據(jù)庫
if ($type == "" || $parent_id == "") {
    exit(json_encode(array("flag" => false, "msg" => "查詢類型錯(cuò)誤")));
} else {  
    // 鏈接數(shù)據(jù)庫
    $sql="select *from global_region where parent_id=$parent_id AND region_type=$type";
    $result=$mysqli->query($sql);
    if($result->num_rows>0)
    {
        $arr=[];
        while ($row=$result->fetch_assoc())
        {
            $arr[$row["region_id"]]['region_id']=$row["region_id"];//$arr[1]["title"]=$row["title"]
            $arr[$row["region_id"]]['region_name']=$row["region_name"];//$arr[1]["content"]=$arr["content"]
        }
    }
    $provinces_json = json_encode($arr);//數(shù)組轉(zhuǎn)json
    exit($provinces_json);
}
?>

実行結(jié)果:

#

學(xué)び続ける
||
<?php echo "省份自動(dòng)加載";
提出するリセットコード