Passando uma função de retorno de chamada para a função de sucesso do jQuery AJAX
Eu estou tentando passar em uma função para executar quando a chamada AJAX é bem-sucedida, no entanto, não está funcionando como diz que "callback não é uma função".
Exemplo:
Código de Chamada:
getGrades(var);
JS:
function getGrades(grading_company) {
// Set file to get results from..
var loadUrl = "ajax_files/get_grades.php";
// Set data string
var dataString = 'gc_id=' + grading_company;
// Set the callback function to run on success
var callback = 'showGradesBox';
// Run the AJAX request
runAjax(loadUrl, dataString, callback);
}
function showGradesBox(response) {
// Code here...
}
function runAjax(loadUrl, dataString, callback) {
jQuery.ajax({
type: 'GET',
url: loadUrl,
data: dataString,
dataType: 'html',
error: ajaxError,
success: function(response) {
callback(response);
}
});
}
Agora, se eu substituir esta linha abaixo pelo nome da função, ela funciona:
callback(response);
Mas não consigo fazer funcionar como acima, onde recebo o nome da função de um parâmetro passado.