如何在php中选择另一个网站的值时填充dropdownbox的值


how can i populate the value of dropdownbox while selecting the value of another website in php

我有两个下拉框,一个用于国家,另一个用于州

我该怎么办?我会从第一个下拉框和中选择国家

第二个下拉框应填写相关国家的州名

我想使用jquery和PHP

国家和地区存储在mysql数据库中

如何使用Jquery、Ajax、PHP和Mysql进行动态相关的选择框。从属选择框当在"父"框中进行选择时,它允许刷新"子"框列表数据。

http://www.9lessons.info/2010/08/dynamic-dependent-select-box-using.html

当您所在国家/地区下拉列表的选定值发生更改时,将触发以下代码。

然后,您可以使用PHP脚本返回一个JSON状态列表,然后将其填充到状态下拉列表中。

$('#IdOfYourCountryList').change(function(){
    var country = $(this);
    $.getJSON("UrlOfYourPHPScript", function(result) {
        $.each(result, function() {
            options.append($("<option />").val(this.Value).text(this.Key));
        });
    });
});

this.Keythis.Value指的是每个选项所需的名称和值,名称可能会根据JSON的结构而变化。

这类事情的例子的音调。谷歌是你的朋友。以下是一个示例:http://roshanbh.com.np/2008/01/populate-triple-drop-down-list-change-options-value-from-database-using-ajax-and-php.html