javascript - "Waiting" for ReadyState to be 4 before returning a value -
i have looked in lots of places this, , i'm being idiot because done lot, here's situation.
i trying display checkbox next e-mail field on website iff e-mail has not been used register already.
what have this:
$('[name=reg_email]').change( function() { if(!emailused()) { //update image green checkmark } else { //update image huge red x } } and "emailused" function should returning javascript boolean variable depending on whether or not e-mail address in database. facilitate this, i've created script determine if it's there or not. emailused() function needs call script , return, need wait until readystate == 4 before return, , of methods have found waiting readystate equal 4 prevent me returning value @ all:
function emailused() { var req = $.get('scripts/email_used.php?email='+$('[name=reg_email]').val()); //wait req.readystate 4 return req.responsetext == 'true'; } but can find explains how , still return value. seems use callback functions , , that, can't method return value.
help, please!
doing busy wait req.readystate === 4 considered bad design practice. you're tying ui thread , preventing browser updating. if server slow enough respond, user prompted whether cancel further processing.
if take @ $.get(), takes completion function 1 of arguments. should perform success/failure logic in function. can disabling submit button until success message.
Comments
Post a Comment