Create CAPTCHA in Classic ASP CAPTCHA with JQuery

No.of Views2089
Bookmarked0 times
Downloads 
Votes0
By  dotnetfish   On  09 Sep 2010 08:09:23
Tag : ASP , Miscellaneous
It come to the point that i need to maintain my old application which written in ASP. I was asked to add a new feature in form submission to prevent from spamming
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Introduction

It come to the point that i need to maintain my old application which written in ASP. I was asked to add a new feature in form submission to prevent from spamming. CAPTCHA is the thing that i could thought of Thanks Emir Tüzül who willing to share his ASP CAPTCHA. You can download it from http://www.tipstricks.org/

Implementation

I downloaded the code and modify the code so that the security checking is before the asp postback. The solution i could thought of is AJAX. When i thought of javascript, the coolest javascript framework will be JQuery.

The decision is go for JQuery in order to perform Ajax with ASP.

There is one concern, the application will need to perform cross domain ajax. If use normal jquery ajax (code below), it will work if all the file reside in the same domain but not when cross domain.The Error 'Permission denied to call method XMLHttpRequest.open"

var html = $.ajax({ 
url: "/captcha.asp?validateCaptchaCode=" + $("#captchacode").val(), 
async: false 
}).responseText;

 In our case, the file put in different domain. The technics will be use is Cross-Domain getJSON (using JSONP). Sample code below

$.getJSON("captcha.asp?validateCaptchaCode=" + $("#captchacode").val() + "&format=json&jsoncallback=?", function(data)
{ 
if (data.status == "1") 
{ alert("verified and submit."); 
$("#form").submit(); 
result = true; 
} 
else 
{ 
if (data.session == "0") 
RefreshImage("imgCaptcha"); 
alert("Please key in the security key correctly!"); 
$("#captchacode").focus(); 
result = false; 
} 
});

 The Cross-Domain getJSON will espect the data return in Json format. So, my ajax handler file (in my case is captcha.asp) will need to return Json format data for processing.After develop and tested. It's work. You can download my sample file below and test on it. Please let me know if it's help.

Sample Project Source 

Download source files -36 kb

 
Sign Up to vote for this article
 
About Author
 
dotnetfish
Occupation-
Company-
Member Type-Senior
Location-United States
Joined date-05 Sep 2010
Home Page-www.xininvoice.com
Blog Page-dotnetfish.blogspot.com
 
 
Other popularSectionarticles
    Comments
    By:aDate Of Posted:4/4/2012 12:26:47 AM
    a
    hgfh
    By:ghjghjDate Of Posted:5/9/2011 7:10:35 AM
    yjghj
    dafsdfsdfsdfsd
    Leave a Reply
    Title:
    Display Name:
    Email:
    (not display in page for the security purphase)
    Website:
    Message:
    Please refresh your screen using Ctrl+F5
    If you can't read this number refresh your screen
    Please input the anti-spam code that you can read in the image.
    ^ Scroll to Top