1
I have a $('form'). on('Submit', Function()); and inside it I would like to make a call from a function that runs an ajax and returns an array of data. however when saving the return of the function in a variable the same becomes "undifined" it is not possible to do what I want?
Follow the example code:
Fom Submit:
$('#form_independentes').on('submit', function(event) {
let curso_id = 1;
let ficheiros = getDocuments_(curso_id);
// variavél ficheiro fica como undefined
});
Function getDocuments_ :
function getDocuments_(id_curso){
$.ajax({
url: '/candidaturas/documents/'+id_curso,
type: 'GET',
dataType: 'json',
success: function( _response ){
//este console log mostra um array de objetos
console.log(_response.documents)
return _response.documents;
},
error: function( _response ){
Materialize.toast('Opps ocorreu um erro. por favor atualize a página e volte a tentar', 4000, 'red');
return false;
}
});
}
Also below is a screenshot of the console showing Undefined and the object array
at the url of
ajax
you are taking the information from PHP and passing the information using thejson_enconde($array)
?– DNick