473,404 Members | 2,213 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

making javascript block from execution

I'm having trouble finding a way to get javascript block from execution.

I have a html form where a user enters email and password

I want to do basic validation in javascript
(1) email is entered
(2) password is entered

If both are not NULL then I call ajax (jquery - model) make a call to backend php to validate if the email and password is correct - During this period of time - I want the javascript to block from further execution.

Once the response comes from backend php, I want to unblock javascript.

Also, I want a timeout - incase backend php doesn't respond - so that I can throw a message - "server is busy. please try again later"

Could someone tell me how this can be achieved using javascript, jquery.

Much thanks in advance.
Tony
Jul 31 '10 #1
7 5407
Jyoti Ballabh
115 100+
One of the methods would be to block script execution by using a loop, which will also lock up the browser and prevent any interaction with your web page. You could write simple codes in narrative javascript.
Expand|Select|Wrap|Line Numbers
  1. username/ password.onload = new EventNotifier();
  2. username/ password.onload.wait->();
Once you preprocess it you get the pure javascript.
Aug 1 '10 #2
Jyoti Ballabh
115 100+
The whole point is that you do not want to block script execution completely, as that could make the browser slow down, or even alert the user that a script is taking too long to execute. You could 'linearize' your code by using events to finish work. You will need to add a time out to the function, as the password may never load.

Expand|Select|Wrap|Line Numbers
  1. var _password = null; 
  2. var _passwordDelay = 0;
  3. var _finished = false;
  4.  
  5. function startWork(){
  6.    _password = document.createElement('password');
  7.    _password.onload = onPasswordLoaded;
  8.    _password.src = 'yourpassword.png';
  9.  
  10.    // append password tag to parent element here
  11.  
  12.    // this is a time out function in case the password never loads,
  13.    // or the onload event never fires (which can happen in some browsers) 
  14.    passwordTimeout();   
  15. }
  16.  
  17. function passwordTimeout(){
  18.    if (_password.complete){
  19.       // password is really done loading
  20.       finishWork();
  21.    }
  22.    else{
  23.       // calls recursively waiting for the img to load
  24.       // increasing the wait time with each call, up to 12s
  25.       _passwordDelay += 3000;
  26.  
  27.       if (_passowrdDelay <= 12000){ // waits up to 30 seconds
  28.          setTimeout(passwordTimeout, _passwordDelay);
  29.       }
  30.       else{
  31.          // password never loaded, recover here.
  32.       }
  33.    }
  34. }
  35.  
  36. function onPasswordLoaded(){
  37.    finishWork();
  38. }
  39.  
  40. function finishWork(){
  41.    if (!_finished){
  42.       // continue here
  43.       _finished = true;
  44.    }
  45. }
  46.  
Aug 1 '10 #3
iohos
45
@ Spettro- ok, for time being let's forget about all this javascript blocking and password/ email validation. Let's say I have this entirely different problem where I have execute a piece of code, where I start to upload an image and while it's being done block the script execution and the image is fully loaded resume the execution. Then I go on to finish executing the rest of the code. I know the first thing that you might say is the best approach would be to assign a function on the onload event of the image and then execute the rest of the code in the function, but if it's possible I want to have a "linear" behaviour blocking the script execution and then resume it. What would you recommend?
Aug 1 '10 #4
Jyoti Ballabh
115 100+
I would say follow the same approach as I had listed earlier. The function related to image and video upload could have applications but again do not lay so much stress on the "linearity" of the script or using the narrative javascript. After all, it's only a small extension to the JavaScript language that enables blocking capabilities for asynchronous event callbacks.
Aug 1 '10 #5
gits
5,390 Expert Mod 4TB
except with using syncronous calls it is useless to try to make a 'linear' code execution with 'non-linear' behaving async requests. the only and useful way to make use of ajax-calls is to use its events with associated callbacks. by just blocking some execution you could even make sync calls - and when that really is to be used ... then use them sync instead of creating a probably unreliable and overhead-creating logic for something that is much easier done with just a sync call - but as i said already: async usage is much to prefer and when you use async requests - the code is non-linear - at least written - chaining everything correctly through the event-chain will make it linear ... that is the real purpose of the thing called AJAX ...
Aug 1 '10 #6
Frinavale
9,735 Expert Mod 8TB
I might be wrong here but isn't @tony waria looking for a modular control that blocks access to the page while the page is processing?

This would force the user to wait while Ajax calls (or full post-back requests)are occurring...essentially informing the user that processing is taking place and forcing them to wait before doing something else.

This is pretty easy to achieve and can be used very nicely when Ajax calls are involved.

If this is what you're looking for, say so and I can elaborate.


Aside: @iohos who is Spettro?????

-Frinny
Aug 3 '10 #7
iohos
45
Spettro is JB's nickname. I am sorry, I shouldn't have used it here. I just do it out of compulsiveness.
Aug 5 '10 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Steve | last post by:
I just noticed, in IE6, when navagating from one page to another with the same basic layout (centered top graphic, for example), that a page with a <script> block in the <head> shifts the HTML...
0
by: ruca | last post by:
I have a file with javascript programming (in this case is a run time clock, that display hours and date at real time). In my old application I have this clock displying where I want, but now in...
4
by: Cliff Harris | last post by:
Is there a way for me to globally add a javascript block to all pages? I was hoping I could use one of the application events, but I don't seem to have access to the page object to use...
7
by: joey.powell | last post by:
I have a home page with username and password textboxes and a login button for purposes of users being able to log in (forms authentication) directly on the site home page. I also have a dedicated...
2
by: Laphan | last post by:
Hi All I'm using ASP to squirt some text into JS so that the JS write it into an iFrame, but JS keeps giving me unterminated string errors when the text is more than 1 line's worth. I thought...
4
by: Lunchtimemama | last post by:
I have a UI with a gallery of thumbnail image previews. The PictureBoxes are created and their Images are generated by a method which quickly retrieves the icon for the filetype. Worker threads...
10
by: Shadow Lynx | last post by:
That subject packs a whallop, so let me explain in better detail what's happening and how it relates to ASPX pages... In a nutshell, if the first <script /on a page is of type "text/vbscript",...
14
by: maidane | last post by:
Hi, I got the following situation using the AC_Quicktime library. Apple recommend to use a Javascript call to generate the OBJECT tag (http://developer.apple.com/internet/ieembedprep.html). I...
18
by: Tom Cole | last post by:
I'm working on a small Ajax request library to simplify some tasks that I will be taking on shortly. For the most part everything works fine, however I seem to have some issues when running two...
2
by: CalebConnolly | last post by:
Hi could you help me, I want to write a program that Writes a function that displays at the left margin of the screen a solid square of asterisks whose side is specified in integer parameter side....
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.