x_maras Posted April 15, 2010 Share Posted April 15, 2010 Hi, I am trying to learn ajax so I decided to make a simple captcha. The good thing is that it works the bad thing that it has an one click late response... I will try to explain you what I mean with one click late response. I have a a form and instead of submit button I have a normal button which onclick calls 2 functions. <input name="submit" value="Eisagwgi" type="button" onclick="testCaptcha(); calculateLatLng();"/> The first checks the captcha and if its right then stores '1' in a global var. The second one checks this global variable (and some other checks and calculations) and if the value is '1' then inserts some data in a database. else shows a message next to the captcha box. So when I press this button and the captcha is wrong it shows the false message. If the the inserted captcha is right in the first click shows the false message and if I click again the button shows the correct message and continue with the database thing. I would really appreciate it if someone could explain me why this happens. I could also post my code (it is not a secret) but I didn't want to make the already big post, bigger. Thank you in advance, Dinos Quote Link to comment Share on other sites More sharing options...
seventheyejosh Posted April 15, 2010 Share Posted April 15, 2010 I hope you're also putting in some server side checking of that captcha. All someone has to do is disable javascript... and bam!, brute force / spam! Quote Link to comment Share on other sites More sharing options...
x_maras Posted April 15, 2010 Author Share Posted April 15, 2010 Yes of course I do! But I don't know if I will ever use this code in an online application. I just want to figure out why this happens Quote Link to comment Share on other sites More sharing options...
seventheyejosh Posted April 15, 2010 Share Posted April 15, 2010 If the second function is relying on the first resolving, you may need to stall the second one's call. onclick="a(); setTimeout(function(){b();},1000);" Will run the first function, which will update globals, etc, and then, one second later, run the other. It could just be that your first function is taking too long to process. Quote Link to comment Share on other sites More sharing options...
x_maras Posted April 15, 2010 Author Share Posted April 15, 2010 Thanks a lot!!! That worked perfectly Quote Link to comment Share on other sites More sharing options...
seventheyejosh Posted April 15, 2010 Share Posted April 15, 2010 No problem, whenever you do advanced ajax stuff, you need to make sure you're allowing time for your ajax request to resolve. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.