Page 1 of 1

Auto Complete From Json

Posted: Wed Sep 10, 2014 10:05 am
by Grandong
i try to get location by API request
here the ex url for request api :

Code: Select all

https://api.master18.tiket.com/search/autocomplete/hotel?q=mah&token=90d2fad44172390b11527557e6250e50&output=json
Where if user type mah show auto complete from api request, this json result

Code: Select all

{"output_type":"json","diagnostic":{"elapsetime":"0.1383","memoryusage":"6.33MB","lang":"id","currency":"IDR"},"result":[{"id":"business:3772","label":"Puri Maharani Boutique Hotel & Spa - Denpasar, Denpasar Timur, Kesiman Kertalangu","value":"Puri Maharani Boutique Hotel & Spa","category":"Hotel"},{"id":"business:3852","label":"Maharani Hotel - Jakarta Selatan","value":"Maharani Hotel ","category":"Hotel"},{"id":"business:3874","label":"Maharadja Hotel - Jakarta Selatan, Mampang Prapatan, Tegal Parang","value":"Maharadja Hotel","category":"Hotel"},{"id":"business:4776","label":"Pita Maha Resort and Spa - Gianyar, Ubud, Ubud","value":"Pita Maha Resort and Spa","category":"Hotel"},{"id":"business:4779","label":"The Royal Pita Maha Resort and Spa - Gianyar, Ubud, Kedewatan","value":"The Royal Pita Maha Resort and Spa","category":"Hotel"},{"id":"business:18420","label":"Villa Mahapala Bali - Denpasar, Denpasar Selatan, Sanur","value":"Villa Mahapala Bali","category":"Hotel"},{"id":"business:105246","label":"Mahagiri Dreamland Villas & Spa - Badung, Kuta Selatan, Pecatu","value":"Mahagiri Dreamland Villas & Spa","category":"Hotel"}],"token":"90d2fad44172390b11527557e6250e50"}
Please, give me ex javascript auto complete code..
thx very much
:D

Re: Auto Complete From Json

Posted: Wed Sep 10, 2014 10:15 am
by Celauran
Here

At least make an effort.

Re: Auto Complete From Json

Posted: Sun Sep 14, 2014 8:20 am
by Grandong
Celauran wrote:Here

At least make an effort.
Sorry Celauran...

if just autocomlete, this no problem, but my problem is, get data from api request and display in autocomplete.
this my php code :

Code: Select all

                      <?php foreach($json_results['all_airport']['airport'] as $result): ?>
                       <?= $result["location_name"]; ?>
                      <?php endforeach; ?>
and this my jquery:

Code: Select all

var availableTags = [
<?php echo $result["location_name"];?>
];
        s( "#chotel" ).autocomplete({
        source: availableTags
    });
But, Not Work For Me..
Help Please...