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 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题