doutuo1939 2014-03-28 23:38
浏览 86

form.submit()发布复选框数据与标准提交按钮不同吗?

I just ran into an odd issue with my CodeIgniter app. I'm using a jQuery .on('submit') event handler to catch all form submissions and follows this procedure: grab the form object using this, stores the object for later, checks the user is logged in with an AJAX call, if logged in, gets the stored jQuery form object and submits the form with form.submit().

This works absolutely fine for all my forms (form validation works fine, returns validation errors correctly) except when I have a form with a checkbox. The checkbox is just ignored.

I use a required form validation rule to make sure the user ticks the checkbox before continuing and it works absolutely fine when this event handler is disabled however, the validation error only appears (oddly) when I add another input to the form that isn't a checkbox!

I'm wondering if there's someone that can understand the theory behind why this error is happening? I could post the code but I'm about 90% sure this is something to do with the way that JavaScript handles posting of checkbox data that I'm just not aware of.

Any ideas?

  • 写回答

2条回答 默认 最新

  • doucheng1944 2014-03-28 23:42
    关注

    Javascript, by itself, doesn't actually post any form data.

    In the standard HTML submit, if a checkbox is not checked, then there is no key/value submitted for that item.

    I've learned the hard way that many Javascript form serializers (used by Ajax calls) are simply broken and don't follow the standards... I spend several days writing my own and my Qunit tests are almost longer than the code itself.

    What you'll need to do is use your debugging tools (Firefox or Chrome) and watch the network tab -- see exactly what is submitted.

    评论

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路