Jump to content

stop from loading??


acidglitter

Recommended Posts

on a site i'm making, you click a button that calls ajax to add that product to your shopping bag. it takes a little while to load though so i'm worried someone will click the button, then while its still loading, click it again and call the function all over again. is there a way you can prevent the function from starting if it has already started? (if that makes sense ;))

Link to comment
Share on other sites

You can set the button to disabled at the start of your function. I believe you do it like this:

 

this.disabled = true

 

If this is the first command in your onclick script, the button will be disabled for the rest of the script. If you want the button to be usable again at some point, you will have to use:

 

this.disabled = false

 

in order to re-enable it.

Link to comment
Share on other sites

hi

 

when u call ajax at that time disable the submit button till u get request from server with the help

of ajax

 

 

when ajax is working /processing the request submit button will be disabled

 

as soon as ajax processing is over submit button will be active.

 

 

 

 

Link to comment
Share on other sites

I can only think of a hack of sorts in order to disable a text link. Its not the greatest solution, and maybe someone else can come up with something better than this, but you could do this:

 

- When the script is executed, immediately create an element with a unique ID name and a display set to none, and append it somewhere on the page

- At the end of your script, remove this appended element

- At the very start of the script (even before step 1), check to see if the element with said unique ID exists. If it does, then return false (which will exit the script).

 

By doing this the script will not run if clicked a second time, as it has not finished running the first time. However, you are appending unneeded elements to your page which is why its not the greatest solution.

 

I've never done this, but it will work except for the situation where someone manages to click the link for as second time before the element is appended on the page. But this appending should be too fast for someone to be able to do that.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.