This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes Restrict multiple calls of function Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Restrict multiple calls of function" Watch "Restrict multiple calls of function" New topic
Author

Restrict multiple calls of function

anand phulwani
Ranch Hand

Joined: Sep 10, 2005
Posts: 242
Dear Ranchers,

I have created a tree in javascript whose nodes calls a function
for example

Now this function takes approx. 30-40 seconds to complete,
and if i click on this node,the function starts its processing
and if in the meantime i click on the other nodes,it generates an error

This happens due to multiple requests of the script,
i wish to block request until response of one is rendered,
i have also tried to do this with a flag called allowrequest,but the ealier script dies as soon as the new request arrives.



Please advice what to do in this case and how can i restrict another call until one response completes.


Thanks and Regards, Anand
SCJP 5.0 310-055 73%, SCWCD 1.4 310-081 78%, IBM DB2 9 Fundamentals 000-730 62%
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
add a processing flag saying an action is happening so do no process. Also add an annimation graphic or message to the user omething is happening.

Eric
anand phulwani
Ranch Hand

Joined: Sep 10, 2005
Posts: 242
Thanks for your reply eric,
Is there no way to stop this by programming?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61106
    
  66

30 to 40 seconds to complete a task is pretty outrageous. What's it doing? An Ajax request? I have many Ajax requests that do intensive processing and that return almost instantly. What's taking so long? Perhaps that's what you should be conentrating on.

Also, there's no inherent reason that your page can't be doing multiple things at a time. What is the cause of the error that you are seeing?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
anand phulwani
Ranch Hand

Joined: Sep 10, 2005
Posts: 242
Dear Bibeault,

Thanks for your time,
It's an Ajax request which GETS 9 JSP pages and renders the response on the page.

The cause of the error is when i click multiple nodes and that too very quickly,i get the error



if you want,i can post the code for further reference.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61106
    
  66

It's an Ajax request which GETS 9 JSP pages and renders the response on the page.


But what is taking so long? And 9 JSPs? That's rather odd.
anand phulwani
Ranch Hand

Joined: Sep 10, 2005
Posts: 242
Dear Ranchers/Bibeault,

Please have a look at the page
Products

Choose Electrical Appliance
Then Select Barbeque.
The dummy data in the database has one or maximum two products for the other categories,the barbeque has 31 i suppose.

Each page shows 9 slides at a time which are Ajax calls for JSP page
Slide.jsp

Slide.jsp picks the data from database and takes every Full Image and then resizes it with a GD library + PHP file.

Your suggestions and comments are invited.
anand phulwani
Ranch Hand

Joined: Sep 10, 2005
Posts: 242
Dear Ranchers,

One more thing the Client has asked to remove the Working On Your Request window,which locks the tree for further request.His opinion is that if a person clicks a wrong category by mistake he has to wait for the products to load of that category,which he is not encouraging.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61106
    
  66

Ah, I though you meant 9 serial JSPs (as opposed to parallel). That would have been very odd.

It all worked fairly quickly for me, with the "working window" being displayed for only a few seconds.

I agree with the client -- that's a rather unfrienldy way to be dealing with your JS bug. Your new plan, which seems to be to ignore the user clicks, isn't any friendlier.

You should be able to simply abort the pending Ajax requests when the user selects something else from the tree, and start over. It's a matter of properly structuring the code.

There's obviously a lot of client side code for that page -- a lot of which seems to be auto-generated dreck from Dreamweaver or similar tool -- so it's hard to give you any concrete suggestions at this point other than to use good coding patterns and object-oriented techniques.

To start with, you'll need to isolate what causes the bad reference when the tree gets clicked on a second time.
[ April 29, 2007: Message edited by: Bear Bibeault ]
anand phulwani
Ranch Hand

Joined: Sep 10, 2005
Posts: 242
Dear Bear/Ranchers,

Thanks for sparing your valuable time,
Please See that i have removed the Working.. Window,
When i am clicking the nodes quickly its generating the error on IE6 and IE7,and as we know netscape and mozilla have some javascript debugging window but that's of no use as it works perfectly on mozilla as well as netscape.

Please Check i really need some help on this as i am not able to trace the bug.I can pass the source code as well as a FTP access to the server for the modifications and testing.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Restrict multiple calls of function