2

私はただの初心者です。データベースからphp,jquery and ajaxをフェッチしたいのです。私のデータベースはこのようなものですstate and city namecountry 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 パスを確認し、問題を追跡できるように、より明確にしました。

4

2 に答える 2

0

ここでできることは、国のドロップダウン値が jquery ajax に変更されたときに呼び出しを行い、選択した国のすべての州を取得し、ドロップダウンに入力して html に追加することです。次に、同じプロセスに従って、選択した州の都市を呼び出します。

于 2013-09-17T14:47:43.477 に答える