Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #19865 > unrolled thread

asyncronous call

Started by"Tony" <tony.johansson@inport.com>
First post2013-05-21 12:28 +0200
Last post2013-05-22 01:07 +0700
Articles 2 — 2 participants

Back to article view | Back to comp.lang.javascript


Contents

  asyncronous call "Tony" <tony.johansson@inport.com> - 2013-05-21 12:28 +0200
    Re: asyncronous call JJ <duh@nah.meh> - 2013-05-22 01:07 +0700

#19865 — asyncronous call

From"Tony" <tony.johansson@inport.com>
Date2013-05-21 12:28 +0200
Subjectasyncronous call
Message-ID<knfi02$jl4$1@dont-email.me>
When I fetch data from the database I display these in either a html table 
control or in a html select control.
I hope to use the same function that fetch these data.
I use this GetData function. There is a small problem here because 
show_Frsvoyage is using json and asynchonous call.
I pass an argument myBool. If this is true I would display data in a html 
table else display in select control.

The work done is GetData where the check is done on myBool is not working 
when  we have calls like these two
GetDataForTable(false, "");
GetDataForTable(true, "");

When I have done this call GetDataForTable(true, "");
I would assume that myBool is true but almost always it's false.

So my question is if it's possible to use only one function to get data by 
using some kind of workaround or do I have to use two functions to
get data

function GetData(myBool, Vesselname)
       {
           //index holder for array
           var i = 0;

           //false means get all records that fulfill the search condition 
on server
           //You get duplicate on vesselname
           show_Frsvoyage(myBool, Vesselname, function (data, textStatus, 
jqXHR)
           {
               if (IsOkMessageShort(data.dsError))
               {
                   // Clear array
                   voyageArr = [];
                   $.each(data.dssFrsvoyage.ttsFrsvoyage, function (key, 
value)
                   {
                       // Replace T with "" and "-" with "/"
                       value.Arrtime = value.Arrtime.replace(/-/g, 
'/').replace(/T/g, ' ').substring(0, 16);
                       value.Deptime = value.Deptime.replace(/-/g, 
'/').replace(/T/g, ' ').substring(0, 16);

                       //Add to array
                       voyageArr[i++] = { Arrtime: value.Arrtime, Deptime: 
value.Deptime, Vesselid: value.Vesselid, VesselName: value.VesselName, Port: 
value.port, NextPort: value.nextport, PrevPort: value.prevport }
                   });

                   if (myBool == false)
                   {
                       //Sort the array
                       Sort("Vesselid_Arrtime");

                       //Display the array
                       Display("table");
                   }
                   else
                   {
                       //Sort the array
                       Sort("VesselName");

                       //Display the array
                       Display("select");
                   }
               }
           });
       }

I can solve this problem by using two different functions that fetch data 
from the database but I would rather use only one function as I said before.

//Tony

[toc] | [next] | [standalone]


#19884

FromJJ <duh@nah.meh>
Date2013-05-22 01:07 +0700
Message-ID<1eeajz94uwbte$.161ddepa6t91g.dlg@40tude.net>
In reply to#19865
Don't use asynchronous functions as synchronous functions.
It'll never work as expected.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web