如何处理jquery ajax注释和验证码
我正在社交网络上开发评论系统,我正在使用jquery,我可以毫无问题地使用ajax发布评论,但有时如果用户发布太多评论或出于其他原因,我需要用户提交验证码表单。
我认为最好的方法是将其添加到当前评论发布部分,如果php脚本返回响应,说明我们需要做一个验证码表单,那么我想在屏幕上,让用户填写验证码表单,然后继续并在那里发布评论。
这对我来说有点复杂,但我想我已经完成了大部分工作,也许你可以阅读下面的评论并帮助我解决验证码部分,主要是关于如何触发打开对话框,如何传递评论值/通过验证码发送文本,并在成功时再次返回评论,如果用户得到验证码错误,那么它将重新加载验证码
$.ajax({
type: "POST",
url: "processing/ajax/commentprocess.php?user=",
data: args,
cache: false,
success: function (resp) {
if (resp == 'captcha') {
//they are mass posting so we need to give them the captcha form
// maybe we can open it in some kind of dialog like facebox
// have to figure out how I can pass the comment and user data to the captcha script and then post it
} else if (resp == 'error') {
// there was some sort of error so we will just show an error message in a DIV
} else {
// success append the comment to the page
};
}
});
I am working on a comment system on a social network, I am using jquery, I can post the comments with ajax with no problem but sometimes I need a user to submit a captcha form if they are posting too many comments or for other reasons.
I think the best way to do this is to add it into the current comment posting part, if the php script returns a response, stating that we need to do a captcha form, then I would like to auto open up a dialog window on the screen, let the user fill in the captcha form, then carry on and post there comment.
This is somewhat complex for me but I have most of it done I think, maybe you can read my comments below and help me with the captcha part, mainly on how I can trigger a dialog to open, how I can pass the comment value/text through the captcha and back to the comment backen again on sucess and also if the user gets the captcha wrong, then it will reload the captcha
$.ajax({
type: "POST",
url: "processing/ajax/commentprocess.php?user=",
data: args,
cache: false,
success: function (resp) {
if (resp == 'captcha') {
//they are mass posting so we need to give them the captcha form
// maybe we can open it in some kind of dialog like facebox
// have to figure out how I can pass the comment and user data to the captcha script and then post it
} else if (resp == 'error') {
// there was some sort of error so we will just show an error message in a DIV
} else {
// success append the comment to the page
};
}
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想我会选择使用jQuery UI 库附带的模式对话框。 然后,我将 AJAX 调用包装在一个函数中,这样我就可以递归地调用它。 我将创建一个 DIV (#captchaDialog) 来处理显示验证码图像和一个用于输入答案的输入 (#captchaInput)。 当用户单击模式对话框上的“确定”按钮时,我将使用新的验证码响应修改原始参数并调用该函数。 由于此解决方案只是修改原始参数并将其重新传递到相同的 URL,因此我相信此解决方案适合您。
一些示例代码,减去模态对话框的 div 和输入:
希望这有帮助!
I think I would opt for using the modal dialog that comes with the jQuery UI library. Then, I would wrap the AJAX call in a function so I could recursively call it. I would create a DIV (#captchaDialog) that handled displaying the Captcha Image and an Input (#captchaInput) for entering the answer. When the user click the OK button on the modal dialog, I would modify the original args with the new captcha response and recall the function. Since this solution simply modifies the original args and repasses it to the same URL, I believe this solution will work for you.
Some sample code, minus the div and input for the modal dialog:
Hope this helps!
侧面想法:
为了获得最佳用户体验,我会高度考虑实施反向验证码:
http:// /www.ccs.uottawa.ca/webmaster/reverse-captcha.html
我知道这并不能满足您的问题的需要,但我至少不得不提到这一点。 这是一种垃圾邮件预防方法,不需要代表您的用户进行任何输入。
Side thought:
For best user experience I would highly consider implementing reverse CAPTCHA:
http://www.ccs.uottawa.ca/webmaster/reverse-captcha.html
I understand this doesn't address the needs of your question, but I had to at least mention this. It's a spam prevention method that doesn't require any input on behalf of your users.