Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- API di Yii :
- =============
- public function actionView()
- {
- $sql = "SELECT * from tbl_data";
- $connection=Yii::app()->db;
- $command=$connection->createCommand($sql);
- $dataReader=$command->queryAll();
- echo CJSON::encode($dataReader);
- }
- ======================================================
- Di jQuery :
- ============
- $.ajax({
- type: 'GET',
- url: '<?php echo Yii::app()->createAbsoluteUrl("api/view"); ?>',
- dataType: 'json',
- cache: false,
- success: function (result) {
- $.each(result, function() {
- $("#idCombonya").append($('<option>', {
- value: this.strkey,
- text : this.strvalue
- }));
- });
- },
- error: function(jqXHR, exception){
- if (jqXHR.status === 0) {
- alert('Not connect.\n Verify Network.');
- } else if (jqXHR.status == 404) {
- alert('Requested page not found. [404]');
- } else if (jqXHR.status == 500) {
- alert('Internal Server Error [500]');
- } else if (exception === 'parsererror') {
- alert('Requested JSON parse failed.')
- } else if (exception === 'timeout') {
- alert('Time out error.')
- } else if (exception === 'abort') {
- alert('Ajax request aborted.')
- } else {
- alert('Uncaught Error.\n' + jqXHR.responseText);
- }
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement