尝试使用通过单击普通按钮(不是提交按钮)触发的基于 ajax 的提交过程,使用 jQuery 真的很容易。
据我所知,垃圾邮件机器人没有 javascript。
如果您担心没有启用 javascript 的用户,我认为让他们无法提交表单是完全可以的。如果他们不能信任您在您的网站上启用 javascript,那么他们不能最大限度地使用该网站并不是您的错。
编辑:
另请参阅:实用的非基于图像的验证码方法?
但问题是,如果有人故意针对您的网站,这种技术将不起作用。
编辑2:
我无法提供指向现实生活示例的链接,但我在博客中提供了更多详细信息,所以这里有一些示例代码:
function submit_form()
{
jQuery.ajax({
"type": "POST", // or GET
"url": 'action_url', // The url you wish to send the data to, the url you'd put in the "action" attribute on the form tag
"data": jQuery("form#the-form").serialize(), // The data you'll send. You need to get the form somehow. Easiest way is to give it an id.
"dataType": "json", // Only put this if the server sends the response in json format
"success": function(data, textStatus) // server responded with http status 200
{
// This is the happy case: server response has arrived
},
"error": function(req, textStatus, errorThrown) // maybe HTTP 404 or HTTP 500
{
// something went wrong, the response didn't go through or the response didn't come. Handle the situation: let the user know, or something.
},
"complete": function(req, textStatus) // This one always gets called anyway
{
// cleanup after yourself
} // XXX careful: if you put a comma here, IE6 will fail
});
}