Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Lean Karlo Corpuz
6,159 Pointsjson not retuning value
im trying to call call function via javascript. Once user select a country. it will call the function. sends the country code then return the cities on it.
View: <div class="control-group"> <label for="select" class="control-label">Country</label> <div class="controls"> <select name="countries" id="countries" class='input-large' onchange="getCities()"> <?php foreach ($countries as $key => $country) { ?> <option value="{{ $country->CountryCodeFIPS }}">{{ $country->Country }}</option> <?php } ?> </select> </div> </div>
<script type="text/javascript">
function getCities()
{
var cities;
$.ajax({
type: 'GET',
url: '{{ URL::to("admins/doctors/cities") }}',
dataType: 'json',
success: function(response){
cities = response.cities;
alert(cities);
}
});
}
</script>
<div class="control-group">
<label for="select" class="control-label">City</label>
<div class="controls">
<select name="cities" id="cities" class='input-large' >
<option value="1">Choose Country First</option>
</select>
</div>
</div>
ROUTE: Route::get('doctors/cities',array('uses' => 'CitiesController@getCities'));
Controller:
public function getCities()
{
$countryCode = 'RP';
$cities = City::select('City')->where('CountryCode', '=', "RP")->get();
return json_encode(array('City' => $cities));
}