dpir3950 2014-07-21 12:46
浏览 64

当JavaScript被禁用或不可用时,防止使用AJAX提交的表单提交

I have quite a few forms on my site that are submitted using jQuery ajax. When I recently disabled JavaScript to do a bit of testing, I noticed these form submit the usual way.

Is there anything that can be done to prevent them from being submitted at all when javascript is not available or disabled?

My forms do not have a method or action. These are specified in ajax itself. I use a button instead of

Anything I can do to stop them from being submitted?

I know I can generate/enable buttons and things after the page loads, but what if a user were to deliberately disable JavaScript after the page loaded?

  • 写回答

2条回答

  • drau89457 2014-07-21 12:56
    关注

    If you make your submit buttons a div, a or anything other than a tag it will not post using the form wrapper. this allows for a form of graceful degradation based on your needs. when not using the the form doesn't act unless the JavaScript is enabled and listening. using the a tag in a situation like this would allow you to still submit if you wanted but via the ahref attribute and not the form action. also the Internet Explorers might behave differently so keep an eye out and test thoroughly.

    see also: When To Use The Button Element http://css-tricks.com/use-button-element/

    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?