Solved

Calling response.IsClientConnected from Javascript

Posted on 2004-10-27
261 Views
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  
      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.
       
0
Question by:Cybordax
    9 Comments
     
    LVL 63

    Expert Comment

    by:Zvonko
    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.



    0
     
    LVL 13

    Expert Comment

    by: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

     
    :)

    0
     

    Author Comment

    by:Cybordax
    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      
    0
     
    LVL 13

    Accepted Solution

    by:
    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

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

    also
    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 :)

    0
     

    Author Comment

    by:Cybordax
    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

    0
     
    LVL 13

    Expert Comment

    by:nurbek
    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


    0
     

    Author Comment

    by:Cybordax
    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
    0
     

    Author Comment

    by:Cybordax
    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"
    0
     
    LVL 13

    Expert Comment

    by:nurbek
    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




    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Learn The Basics of Ethical Hacking & Pen Testing

    Computer and network security is one of the fastest growing and most essential industries in technology, meaning companies will pay big bucks for ethical hackers. This is the perfect course to leap into this lucrative career, learning how to use ethical hacking to reveal ...

    Both jQuery and Mootools offer some nice, easy to use scripts. Mootools is best known for their interactive slideshows and jQuery for their menus, but both have many other uses as well.   jQuery is basically a toolkit with many DOM (http://en.wik…
    I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
    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…

    846 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

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now