I'm traying to make an ajax action in my project which is developed by Userfrosting system (A system that uses slim framework and twig).
There are 2 html select tags in sections.php called country and city. When country is chosen, cities in that country will ve selected from the database and will be shown in city tag with an ajax action.
I can do this with a normal php script, but can't do it in slim.
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>
Posted value 'veri' will be taken by deneme.php and cities in that country will be fetched from database and all the cities will be listed in options.
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>';
}
When i choose the country, city option becomes empty and i get this error in error log;
"PHP Fatal error: Call to a member function
getAktiviteler()
on a non-object inC:\xampp\htdocs\userfrosting\public\deneme.php
on line 119"
I used many diffent ways but couldn't solve the problem. Please help !