Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Calling response.IsClientConnected from Javascript

Posted on 2004-10-27
Medium Priority
Last Modified: 2012-08-13
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  

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
        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.


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

Thanks in advance people

And have a great and groovy day.
Question by:Cybordax
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
LVL 63

Expert Comment

ID: 12419848
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.

LVL 13

Expert Comment

ID: 12420088
refresh the page every adjusted seconds


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



Author Comment

ID: 12432113
Tried the above for the Session_OnEnd  and it did not work...

basically this is my coding

      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) = ""
      for a = 1 to SOiCount
            for b = 1 to 20
                  ARYSOCart(a,b) = ""
      SOiCount = 0
      iCount = 0
      session("ShoppingCart") = ARYShoppingCart
      session("ItemCount") = icount
      session("SOCart") = ARYSOCart
      session("SOCount") = SOiCount
      application("active")=application("active") - 1

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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 13

Accepted Solution

nurbek earned 2000 total points
ID: 12432243
when you close the broser it doesnt the fire Session_OnEnd directly
check the session time out and  visit the page after a long time > Session.Timeout

in your code
you used Sessions
Sessions also be lost when the session ends

you have to try to use temp table to keep the shopping cart
(do not increase the stcok)
when the user closes the browser delete inside of the table

when the shopping card is completed and submitted (purchased)
then icrease the stock
delete inside of the table

maybe this gives an idea :)


Author Comment

ID: 12432311
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.....


LVL 13

Expert Comment

ID: 12432608
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


Author Comment

ID: 12432635
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

Author Comment

ID: 12433519
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"
LVL 13

Expert Comment

ID: 12433650
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

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



Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question