'AJAX: Can I POST an array/data from my GET request? (Flask)

question similar to AJAX/FLASK/JS: How to POST existing array into endpoint?, a new question I've posted but this doesn't specifically help with the new issue, sorry about that.

I am tying to POST an array, specifically the songFiles array, I have pushed with data from my AJAX GET request. Is there any way I can do this in the same call or any solution at all? Been trying to rack my brain, any help is welcomed, thanks :).

[My first question here, so I might be missing something]

    function getTableData(callback) {
    $.ajax({
        method: 'GET',
        url: '/api/getSong',
        dataType: 'json',
        success: function(data) {
            createMusicTable();
            
            let indexObj = Object.keys(data.song).length;
            
            for (var i = 0; i < indexObj; i++) {
                var song = data.song[i]
                var id = data.song[i].song_id;
                var fileName = data.song[i].song_file + '.mp3';
                
                songFiles.push(fileName);
                appendMusic(song, id);
                
                songTitle.id = "s" + i;
                console.log("td-ok");
                callback(songFiles);
            }
        }
    });
}

function callback(result){
    return fileNames 
}

EDIT FOR COMMENT:

success: function(data) {
           // CODE HERE BLAH BLAH 
                $.ajax({
                    method: 'POST',
                    url: '/someURL',
                    dataType: 'json',
                    success: function(data) {
                       
                    }
                });
            }


Solution 1:[1]

Your question technically asks whether one can send a POST request from a GET request. Another possibility is that you want to send a POST request from the client-side once the GET request completed.

If you want to send it from your GET request, then you will need to modify the /api/getSong endpoint so that it will trigger a POST request from your server. If you do not want to wait for it, you can do it asynchronously. If you intend to wait for it, then you need to do it synchronously. You can build up your response as you like.

If you want to send the POST request from the client-side, then you will need to send it from the success callback.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Lajos Arpad