Return a value from a .done promise

66
May 15, 2018, at 9:20 PM

I am usingthis function to get an array of data from a signalr server I wanted to compare this data in another signalR function where I am getting the new updates.

$.connection.hub.start().done(function () {
  zone.server.getAllZonesAndCarsInfo().done(function (data) {
});

I wanted to get the data as a return value or saved in to a global variable in JavaScript. I tried doing this but I am getting undefined.What am i missing here?

 var update;
   function test() {
     $.connection.hub.start().done(function () {
       zone.server.getAllZonesAndCarsInfo().done(function (data) {
         update = data          
       });
     });
   }
 test()
 console.log(update)
Answer 1
function test() {
     $.connection.hub.start().done(function () {
       zone.server.getAllZonesAndCarsInfo().done(function (data) {
         anotherFunctionYouWantToCall(data)          
       });
     });
   }

You can't save the value to external variable. Instead you can call function anotherFunctionYouWantToCall(data), and compare the received data there.

READ ALSO
How do I use Screenfull.js to make a Google chart fullscreen?

How do I use Screenfull.js to make a Google chart fullscreen?

I am using screenfulljs to allow a Google chart to be viewed in fullscreen

92
Bootstrap table fix header with custom column width

Bootstrap table fix header with custom column width

I want to fix header in bootstrap table with tbody scrollI have search many result but not getting proper answer yet

60
Color on ColorPicker not being picked correctly

Color on ColorPicker not being picked correctly

I am trying to implement a jQuery colorPickerI found eyeCon color picker and I am encountering that for certain colors it just does not allow to set it so:

52
html page external files not loading [on hold]

html page external files not loading [on hold]

I am currently finishing up a website for a client (https://wwwsecondhouseinspain

79