我正在尋找做我的項目,由Userfrosting系統(使用苗條框架和樹枝系統)開發的ajax行動。困惑於苗條的框架和javascript阿賈克斯組合
在sections.php中有2個html標籤,分別叫做country和city。 選擇國家時,該國的城市將從 數據庫中選出,並將在城市標籤中顯示,並顯示ajax動作。
我可以用一個普通的php腳本來做到這一點,但不能做到苗條。
sections.php
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$(".country").change(function() {
var veri = $(this).val();
var dataString = 'veri=' + veri;
$.ajax({
type: "POST",
url: "deneme.php",
data: dataString,
cache: false,
success: function(html) {
$(".city").html(html);
}
});
});
});
</script>
<label>Country :</label>
<select name="country" class="country">
<option selected="selected">--Select Country--</option>
<option value="1">India</option>
<option value="2">United States</option>
<option value="3">United Kingdom</option>
</select>
<br/>
<br/>
<label>City :</label>
<select name="city" class="city">
<option selected="selected">--Select City--</option>
</select>
發佈值「VERI」將在該國採取deneme.php和城市將從數據庫中獲取,所有的城市都將在選擇上市。
deneme.php
require_once("../userfrosting/config-userfrosting.php");
require_once "../userfrosting/models/mysql/MySqlSiteSettings.php";
$veri = $app->request->post('veri');
if (isset($veri)) {
while ($data = $app->site->getCities($veri)) {
$cities = $data[city];
echo '<option value="'.$cities.
'">'.$cities.
'</option>';
}
當我選擇的國家,城市的選擇變空,我也得到錯誤日誌中這個錯誤;
"PHP Fatal error: Call to a member function
getAktiviteler()
on a non-object inC:\xampp\htdocs\userfrosting\public\deneme.php
on line 119"
我用了很多不同的方法,但無法解決問題。 請幫忙!
討論了一個simular問題/解決方案[here](http://stackoverflow.com/questions/38685237/userfrosting-passing-params-async-data-fetching) – thex