简体   繁体   English

将javascript变量传递给ajax

[英]pass javascript variable to ajax

I am working on a site with many forms . 我正在一个具有多种形式的网站上工作。 Most of the forms will be submitted via jquery AJAX. 大多数表单将通过jquery AJAX提交。

I have implemented recaptcha for security but the client does not like it as the words are sometimes difficult to read. 我已经实现了recaptcha的安全性,但是客户端不喜欢它,因为有时很难读懂这些单词。

As an alternate I am looking at honeytrap method for less important forms. 作为替代方案,我正在寻找不重要形式的honeytrap方法。 As I understand In this method I keep a field in the form hidden from normal users via CSS. 据我了解,在这种方法中,我通过CSS对普通用户隐藏了表单中的字段。 So legitimate users will leave the field blank while a bot will fill it . 因此,合法用户会将该字段留空,而自动程序将填充该字段。

Now my question is since I am using jQuery AJAX for form submission, instead of hidden field if form , can't I just pass an extra variable (along with form field variables) from javascript to AJAX. 现在我的问题是,因为我使用的是jQuery AJAX进行表单提交,而不是如果使用form则是隐藏字段,我不能只是将一个额外的变量(以及表单域变量)从javascript传递给AJAX。 (like var secretword = 1) AJAX will check this variable( if secretword == 1 ) and if it is empty(bot will not use javascript to sumbit form so var will be empty) then the form will not be submitted.For legitimate users javascript function will add "1" value to the variable.Is my method as secure as honeytrap? (例如var secretword = 1)AJAX将检查此变量(如果secretword == 1),并且如果为空(机器人将不使用javascript对表格求和,因此var将为空),则该表单将不会提交。对于合法用户javascript函数将向变量添加“ 1”值。我的方法像蜜罐一样安全吗?

NOTE: Website does not work without javascript so need not go into what happens if javascript is disabled. 注意:如果没有javascript,网站将无法正常工作,因此无需研究禁用javascript会发生什么情况。

Please provide me your valuable advice on this. 请为此提供您宝贵的建议。

You're really over-thinking this. 您真的想得太多了。

If you only do legitimate submission via AJAX, make the form's action attribute wrong , and you've effectively accomplished what your proposed solution does: Anybody directly submitting the form without JS will have their submission ignored. 如果您仅通过AJAX进行合法提交,则将表单的action属性设置为错误 ,并且您已经有效地完成了建议的解决方案所要做的工作:任何不使用JS直接提交表单的人都将忽略其提交。

This obviously won't deter anybody from figuring out where you AJAX submissions are going and just spamming that endpoint directly, but neither will your proposed secretword=1 solution or a traditional hidden field. 显然,这不会阻止任何人弄清楚您的AJAX提交的secretword=1 ,而只是直接向该端点发送垃圾邮件,但是您提议的secretword=1解决方案或传统的隐藏字段也不会。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM