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) {
}
});
}
CodePudding user response:
I am not sure I am understanding clearly your question, if you're trying to post something use a POST request not a GET request
CodePudding user response:
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.