Promise

Vediamo di seguito come fare una richiesta Ajax con una promise, in questo caso imposto la chiamata ad un controller php che restituisce un array poi trasformato in formato Json.

La funzione javascript

function result(){
    let url = gset.base + 'admlight/video';
    fetch(url)
    .then(res => {
    if(res.ok) return res.json();
})
.then(json => {
    console.log(json);
})
.catch(err => {
    console.log('Errore di connessione');
});

Questa รจ invece la parte del controller php

function video(){
    $data = array('nome' => 'ciccio', 'cognome' => 'bello');
    echo json_encode($data);
}