Tengo una página html que incluye javascript. En esta página llamo 3 llamadas ajax y espero hasta que terminen.
Estoy usando signalR e intento actualizar la interfaz de usuario desde la función onMessageReceivedSyncTasks(). Si llamo a un selector jquery dentro de aquí, funciona bien. Pero... si trato de llamar a la función IntitalLoad() obtengo un error. ¿Está todo en el mismo ámbito?
Configuración.html
<html> <body> <!-- html code not included --> <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script> <script> $(document).ready(function () { function InitialLoad() { $.when(GetSettings(), GetTimebands(), GetApnList()).done(function (a1, a2, a3) { // UI changes when all 3 ajax functions done }); } function GetSettings() { return $.ajax({ // ajax call 1 }); } function GetTimebands() { return $.ajax({ // ajax call 2 }); } function GetApnList() { return $.ajax({ // ajax call 3 }); } }); <script src="/signalr/dist/browser/signalr.js"></script> <-- microsoft signalr lib --> <script src="/signalr/dist/browser/messagebroker.js"></script> </body> </script> </body> </html>Messagebroker.js
signalrConnection.on("onMessageReceivedSyncTasks", function (eventMessage) { if ($('#table_buttons').length) { $('#table_buttons').DataTable().ajax.reload(); // This selector works fine } InitialLoad(); // Calling a function returns error });Error:
[2021-11-05T13:21:33.643Z] Error: A callback for the method onmessagereceivedsynctasks threw error 'ReferenceError: InitialLoad is not defined'.