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


Groups > comp.lang.javascript > #19865

asyncronous call

From "Tony" <tony.johansson@inport.com>
Newsgroups comp.lang.javascript
Subject asyncronous call
Date 2013-05-21 12:28 +0200
Organization A noiseless patient Spider
Message-ID <knfi02$jl4$1@dont-email.me> (permalink)

Show all headers | View raw


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

Back to comp.lang.javascript | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

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

csiph-web