私はただの初心者です。データベースからphp,jquery and ajax
をフェッチしたいのです。私のデータベースはこのようなものですstate and city name
country name
CREATE TABLE IF NOT EXISTS `propertylocator` (
`store_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`store_name` varchar(255) NOT NULL,
`country_name` varchar(255) NOT NULL,
`state_name` varchar(255) NOT NULL,
`city_name` varchar(255) NOT NULL,
`address` varchar(255) NOT NULL,
`description` varchar(255) NOT NULL
PRIMARY KEY (`store_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ;
INSERT INTO `propertylocator` (`store_id`, `store_name`, `country_name`, `state_name`, `city_name`, `address`, `description`) VALUES
(1, 'My property1', 'India', 'uttar pradesh', 'Ghaziabad', 'Pilkhuwa, Uttar Pradesh 245304, India', 'this is demo test','this is dummy description'),
(2, 'My new Property', 'India', 'Maharashtra', 'Thane', 'Kudavali, Maharashtra 421401, India', 'test propery again', 'another dummy property'),
(3, 'Dummy store', 'United Arab Emirates', 'Sharjah', 'Halwan Suburb', 'Al Ghubaiba - Sharjah - United Arab Emirates', 'this is another dummy store','another text with dummy');
ここに、 用country name
、2 番目用state name
、および用の 3 つのドロップダウンがありcity name
ます。でcountryname dropdown
私はすべてを取得していcountryname
ます。しかし、選択するcountry name(lets say india here)
と州のドロップダウンオプションが表示さuttar pradesh and Maharashtra
れ、両方とも国名がインドであるため、国リストからアラブ首長国連邦を選択すると、その国名のすべての州名が取得されますですUnited Arab Emirates in the database
。同じように、 に適用されますcityname
。私がこのようにやったことすべてのためjQuery ajax
に
<label>Please Select Country</label></td><td>
<div class="country">
<select id="country" name="country" onchange="selectCountry();">
<option value="Select">Select</option>
foreach($countrylist as $country) {
<option value="$country['country_name]" id="$country['country_name]">echo $country['country_name]</option>
}
</select>
関数でselectCountry()
は、私のコードは次のようになります
function selectCountry() {
var state = $('#country').val();
console.log(state);
$.ajax({
type: "GET",
url: "selectstate.php",
data: { sta : state }
}).done(function(html) {
$('#state').html(html);
})
}
selectstate.php には、次のようなクエリがあります
mysql_connect('localhost','root','') or die(mysql_error());
mysql_select_db(propertylocator) or die(mysql_error());
$sDB = new SelectDb();
$data = $sDB->selectStatesById($_GET['sta']);
foreach($data as $row)
{
echo "<option value=" . $row->state . ">" . $row->name . "</option>";
}
しかし、ここでは結果が得られません。404 not found エラーが表示されます。誰かがここで何が問題なのか教えてください。
私のコードにエラーがある場合は、親切に解決してください。コードを正しく理解できるように。ありがとう
更新 URL パスを確認し、問題を追跡できるように、より明確にしました。