function dictRequest() {
    let channelInput = document.querySelector('#channelInput').value;
    let channelItem = document.querySelector('#channelItem').value;

    const request = new XMLHttpRequest();
    request.open('POST', '/dict-memory');
    
    request.onload = () => {
        const data = JSON.parse(request.responseText);

        //Extract channel names as chn
        var channelNames = data["chn"];
        // Show the channel by using 'btn' on submit. The function accepts a array of object and the HTML id. The HTML element gets updated dynamically.
        showChannels(channelNames, "channels");
        showChannels(channelNames, "channelNames");
        
        document.querySelector('#showChannel').onsubmit = () => {
            // When showChannel is submitted, display the contents in "#items" list. Extract the channel name from '#channelNames'.
            console.log("si")
            let chn = document.querySelector('#channelNames').value;
            let items = data[chn]

            // Call the function appendList that updates the dynamically
            appendList(items, "items")

            // Return false to prevent form from submitting
            return false;
        }
    }

    // Send the data to server
    const data = new FormData();
    if (channel.length !== 0 && channelItem.length !== 0) {
        data.append('channelInput', channelInput);
        data.append('channelItem', channelItem);
    }
    request.send(data);

    return false;
}
// Function that handles the Ajax request
Function that handles the Ajax request
Function that handles the Ajax request
function dictRequest() {
    let channelInput = document.querySelector('#channelInput').value;
    let channelItem = document.querySelector('#channelItem').value;
    const request = new XMLHttpRequest();
    request.open('POST', '/dict-memory');
    request.onload = () => {
        const data = JSON.parse(request.responseText);
        var channelNames = data["chn"];
        showChannels(channelNames, "channels");
        showChannels(channelNames, "channelNames");
        document.querySelector('#showChannel').onsubmit = () => {
            console.log("si")
            let chn = document.querySelector('#channelNames').value;
            let items = data[chn]
            appendList(items, "items")
            return false;
        }
    }
    const data = new FormData();
    if (channel.length !== 0 && channelItem.length !== 0) {
        data.append('channelInput', channelInput);
        data.append('channelItem', channelItem);
    }
    request.send(data);
    return false;
}
function dictRequest ( ) { let channelInput = document . querySelector ( '#channelInput' ) . value ; let channelItem = document . querySelector ( '#channelItem' ) . value ; const request = new XMLHttpRequest ( ) ; request . open ( 'POST' , '/dict-memory' ) ; request . onload = ( ) => { const data = JSON . parse ( request . responseText ) ; var channelNames = data [ "chn" ] ; showChannels ( channelNames , "channels" ) ; showChannels ( channelNames , "channelNames" ) ; document . querySelector ( '#showChannel' ) . onsubmit = ( ) => { console . log ( "si" ) let chn = document . querySelector ( '#channelNames' ) . value ; let items = data [ chn ] appendList ( items , "items" ) return false ; } } const data = new FormData ( ) ; if ( channel . length !== 0 && channelItem . length !== 0 ) { data . append ( 'channelInput' , channelInput ) ; data . append ( 'channelItem' , channelItem ) ; } request . send ( data ) ; return false ; }
Function that handles the Ajax request
Function that handles the Ajax request
//Extract channel names as chn // Show the channel by using 'btn' on submit. The function accepts a array of object and the HTML id. The HTML element gets updated dynamically. // When showChannel is submitted, display the contents in "#items" list. Extract the channel name from '#channelNames'. // Call the function appendList that updates the dynamically // Return false to prevent form from submitting // Send the data to server