dongzhanlu0658 2012-08-08 09:37
浏览 23
已采纳

Ajax提交没有正确发生

Guys this is my first question. I have a table which displays the students name and the input fields to enter their exam marks. The table header shows the subjects(its in a while loop) and has an input field to enter max marks for all of them. This max marks is updated thru Ajax. Its not happening properly. If we press submit first time, nothing will happen. If we press submit second time, it submits. If we press third time, it updates twice, if we press fourth time, it updates thrice (the success message shows thrice) Code -

<script>
$(document).ready(function(){
$("#maxmarks<?php echo "$m";?>").validate({

    rules:{

        maxmarks:{

        number: true,

        }

    },
    messages:{

        maxmarks:{

            number: "Please enter a valid marks",

        }

    },
    submitHandler: function(form){

        $("#maxmarks<?php echo "$m";?>").submit(function(){

            $.ajax({

                url : 'components/teacher/performance/maxupdate.php', 
                type : 'POST', 
                data : $("#maxmarks<?php echo "$m";?>").serialize(),
                success : function(res){

                    $('#resultreturn').prepend(res);

                }
            });
            return false;
        }); 

    }                 
 });
 });
 </script>

The form has the same id as the script above. Can someone tell me what is the problem?

  • 写回答

1条回答 默认 最新

  • dongmao9217 2012-08-08 09:44
    关注

    You have the submit handler twice. Once as submitHandler:, then you do it again as .submit()

    One or the other - not both.

    The first time the form is submitted it creates the submit handler (as you told it to with .submit()) but doesn't actually run it.

    The second time it runs it (since you created it earlier), and then creates it again. Each time you run it you get more of them.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图