Created
March 25, 2013 13:33
-
-
Save thyseus/5237121 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function actionFetchAll($term) | |
| { | |
| $query = sprintf( | |
| "select CityName from geodata | |
| where CityName like '%%%s%%' | |
| group by CityName | |
| order by CityName", | |
| $term); | |
| $result = Yii::app()->db->createCommand($query)->queryAll(); | |
| $cities = array(); | |
| foreach($result as $row) | |
| $cities[] = $row['CityName']; | |
| echo json_encode($cities); | |
| } | |
| <?php Yii::app()->clientScript->registerScript('postal', " | |
| $('#Store_zipcode').blur(function() { | |
| $.ajax({ | |
| 'url': '".Yii::app()->controller->createUrl('//store/fetchZipcode')."', | |
| 'dataType': 'json', | |
| 'data': $(this), | |
| 'success': function(response) { | |
| $('#Store_city').val(response.CityName); | |
| $('#Store_latitude').val(response.Latitude); | |
| $('#Store_longitude').val(response.Longitude); | |
| $('#Store_country').val(response.CountyName); | |
| } | |
| }); | |
| }); | |
| "); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment