如何使用php和ajax根据国家/地区编辑状态

时间:2019-05-02 11:21:32

标签: php jquery ajax

如何在编辑时间内从选定的国家/地区获取状态?

这是针对国家/地区:

<div class="col-md-6">
    <select class="select2 form-control custom-select " style="width: 100%; height:36px;" name="country" onChange="getState(this.value);" id="country">
    <option>Select Country</option>
    <?php foreach($countries as $coun) { 
            foreach($ed as $edit) /*edit mode*/
            {

                if($edit->country_id==$coun->id)
                {
        ?>

                    <option value="<?php  echo $coun->id;  ?>" selected="selected"> <?php echo $coun->name; ?> </option>
        <?php 
            }}

                ?>
                    <option value="<?php  echo $coun->id;  ?>"> <?php echo $coun->name; ?> </option>
                <?php


    } ?>
    </select>
</div>

这是针对状态:

<div class="col-md-6">
    <select class="select2 form-control custom-select" style="width: 100%; height:36px;" name="state" id="state-list" onChange="getCity(this.value);">
    <option>Select State</option>

    </select>
    </div>
function getState(val) {
    $.ajax({
        type: "POST",
        url: "getState.php",
        data:'country_id='+val,
        success: function(data){
            $("#state-list").html(data);
            //getCity();
        }
    });
}

1 个答案:

答案 0 :(得分:0)

尝试以下代码:

function getState(val) {
    $.ajax({
        type: "POST",
        url: "getState.php",
        data:{country_id:val},
        success: function(data){
            $("#state-list").html(data);
            //getCity();
        }
    });
}