Link to home
Start Free TrialLog in
Avatar of Cybordax
Cybordax

asked on

Calling response.IsClientConnected from Javascript

Hey people.. hope you are all well

I have a shopping cart that uses ASP session arrays to store the cart data....
My problem is:
    - A customer adds products to the cart, and the stock levels are adjusted accordingly (but does NOT buy them).. GREAT

    - BUT then the customer gets disconnected from the web site for one reason or another (line dropped or simply went to    
      another site).. . NOT GREAT as those products that were in the shopping cart have not been put back into stock and have  
      gone....

I looked on the net and found response.IsClientConnected, which returns true/false   COOL  so my plan was to use a function with these basic parts, which would be on every customers browser.

Every n seconds
  If our customer is NOT conencted
        Put their cart qtys back into stock
  else
        do nothing
  end if

i was also going to put this into the onLoad part in the BODY tag...  but i could not get it to run a ASP function.

Hense, is there a way to run the ASP function from Javascript function, as this onLoad thing seems to like Javascript functions.

OR

Does anyone have any other ideas that would help me out :)

Thanks in advance people

And have a great and groovy day.
       
Avatar of Zvonko
Zvonko
Flag of North Macedonia image

From my point of view does browser side script not help you.

You have to rethink your complete concept.
The problem starts here:
   - A customer adds products to the cart, and the stock levels are adjusted accordingly (but does NOT buy them).. Not GREAT

Better would be to substract the stock amount first on the counter.
That implies more handling and scripting, but that is the only correct way because the items are not sold as long they do not get payd.



Avatar of nurbek
nurbek

refresh the page every adjusted seconds

<META HTTP-EQUIV=Refresh CONTENT="10">  

10 is in seconds

in your asp page you can check it

but the better solution is
using Session On End in global.asa

Sub Session_OnEnd
write the code here that
Puts their cart qtys back into stock

End Sub

 
:)

Avatar of Cybordax

ASKER

Tried the above for the Session_OnEnd  and it did not work...

basically this is my coding

application.lock
      ARYShoppingCart = session("ShoppingCart")
      icount = session("ItemCount")
      ARYSOCart = session("SOCart")
      SOiCount = session("SOCount")
      
      for a = 1 to 100
            ARYShoppingCart(1,a) = ""
            ARYShoppingCart(2,a) = ""
            ARYShoppingCart(3,a) = ""
            ARYShoppingCart(4,a) = ""
            ARYShoppingCart(5,a) = ""
            ARYShoppingCart(6,a) = ""
            ARYShoppingCart(7,a) = ""
            ARYShoppingCart(8,a) = ""
            ARYShoppingCart(9,a) = ""
      next
      for a = 1 to SOiCount
            for b = 1 to 20
                  ARYSOCart(a,b) = ""
            next
      next
      SOiCount = 0
      iCount = 0
      session("ShoppingCart") = ARYShoppingCart
      session("ItemCount") = icount
      session("SOCart") = ARYSOCart
      session("SOCount") = SOiCount
      application("active")=application("active") - 1
      application.unlock      


i have put the "application" lock unlock etc before, after and in between my coding... but still no joy...

Any other ideas...

Thanks in advance
Steven      
ASKER CERTIFIED SOLUTION
Avatar of nurbek
nurbek

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
hmmm...  temp table possibly...

i need to increase the stock (well the stock allocated)

say i have 50 items in stock and 3 people or more go on line...

one adds 10 to the cart, then the other person goes to add the same item, then should see a real time allocation i.e.   50 original stock items minus what is allocated to the web shopper...
so they should see 40, then when the second user adds 5, any other users will see 35 etc...

its pretty much real time stock figures...

a temp table could be good though, cos i could make a prog that sits on the server and polls the database for inactive rows... for say 20 mins, then puts them back into stock upon inactivity...

but i still need to trap when the user quits, or goes to another web site, because they could close the window, down and come back in 5 minutes later, the old cart data would still be in the temp table.....

hmmm

you can only trace the online user
if logged
on logout (do logout jobs)

if the user closes the browser
then the only way you can do is use session_onend

 session on end doesnt the fire the code immediately
but it fires the code :) myabe a bit later

keep the session.timeout less


now THAT sounds like a plan...

i will do that and keep session timeouts to.........  5 mins  for example.....

or for testing purposes....   1 min...

I will get back to you...

Cheers, my friend
Still does not work...

on session OnStart i set the timeout to 1 min
i add something to the cart... and then wait for a min or so....

on the session onEnd thing..
i make it go through the cart array and add various partcodes and qtys to a txt string
then i write to a file....

and look for that file manually....

But... still does not kick in.....

i may just do the thing where i make a program that checks the database every min or so, and checks the last modified time of the rows and if greater than recorded time + 5 mins, then put stock back and delete the row.....
and i will set session timeout to.... 10 mins or something....  then delete regardless of user...


i will try that.....

that should work......

I will accept the answer you gave about "temp table"
I am also using session on end

when the user logged

i got the user_id from database and Session.SessionID
write it to users lo database

on the session on one event

i call the function that  deletes user log from database
like

DeleteUserLog(ByVal UserID, Byval SessionID)


I also immediately didnt see result (didnt delete the users log)

next time i enter the site, i saw that the user log was deleted

anyway