problem in working with ajax
hi everybody,I'm new to jquery and try to use that in my website.but the problem is when i try to check captcha with ajax request via jquery the code does not go on well.here is the code that i used.please help to figure out this:
at first i request tu check that is captcha valid or not and by returning true or false try to insert comments to DB.but program always falls in (else) part of insertComments() function and i confused totally
thanks in advance
- function insertComments() {
test = CheckCaptcha();
loading();
if (test) {
aid = getQueryStringArgs();
$.get('CommentInsertHandler.ashx', { 'Com_text': $('#ctl00_CNTMain_txtText').val(), 'com_name': $('#ctl00_CNTMain_txtName').val(), 'aid': aid["aid"] }, function(data) {
$("#cmtStatus").hide().html(data).fadeIn('slow');
$('#ctl00_CNTMain_txtText').val('');
$('#ctl00_CNTMain_txtName').val('');
$('#ctl00_CNTMain_txtCaptcha').val('');
});
}
else {
$('#ctl00_CNTMain_txtCaptcha').css({ border: 'solid 1px red' });
$('#cmtStatus').empty();
//$('#cmtajax').empty();
}
}
function CheckCaptcha() {
loading();
$.get('Captcha.aspx', { 'captcha': $('#ctl00_CNTMain_txtCaptcha').val() }, function(data) {
if (data == "ok")
return true;
else
return false;
});
}
function loading() {
$('#loading').remove();
$('<div id="loading">منتظر بمانید...</div>')
.insertAfter("#main")
.ajaxStart(function() {
$(this).show();
}).ajaxStop(function() {
$(this).hide();
});
}