我正在使用ajax,json和jquery评论脚本。在jQuery中使用Ajax表单进行验证码的最佳方法?
我大部分的工作除了最难的部分, 如果一个用户发布X个ammount的评论时间ammount,我的php脚本将返回一个“captcha”触发器到我的javascript代码下面,告诉它这个用户需要输入图形验证码之前,我们将在那里的DB评论
下面你将看到我有一个返回值的3个选项:成功,错误和验证码
返回验证码的时候,我想在屏幕上打开一个弹出式对话框并加载我的验证码脚本,到目前为止,所有内容都可以正常工作。
现在我需要使captcha脚本提交,不仅captcha值,而且我的用户评论,所以我只需要填充一个隐藏的表单字段与评论值。很简单,我还没有做到。现在,如果用户获得错误的captcha值,它需要重新加载屏幕,但再次弹出验证码屏幕,并仍然将注释隐藏在表单值中。这是棘手的部分进来。
在阅读我的计划并查看我的代码下面,你认为我是在正确的轨道上?任何建议在更好的方式?
<script type="text/javascript">
$.ajax({
type: "POST",
url: "process.php",
data: dataString,
dataType: "json",
success: function(data) {
if (data.response === 'captcha') {
//they are mass posting so we need to give them the captcha form
// I can send the users sanitized comment through the captcha script somehow
// 'data.comment' is holding the comment value
jQuery.facebox(function() {
// This opens up a facebox dialog on the screen and popolates it with the captcha image and script
jQuery.get('captchabox.php', function(data) {
jQuery.facebox('' + data + '')
data.comment;
})
})
} else if (data.response === 'success') {
// success append the sanitized-comment to the page
$('#comments').prepend(data.comment);
} else if (data.response === 'error') {
// just an alert for testing purposes
alert('sorry there was an error');
};
}
});
</script>
UPDATE:
后更觉得似乎我需要让我的验证码使用AJAX以及否则会出现一个页面重载=(
@jasondavis - 你应该编辑你以前的类似问题,并把它放在一个赏金吧。http://stackoverflow.com/questions/1257991 /如何到交易与 - jqu ERY-Ajax的意见和-验证码 – karim79 2009-08-11 20:29:54