js提交不起作用不发送表格数据到PHP

时间:2015-05-07 12:31:26

标签: javascript php jquery forms

经过一段时间(2分钟),当我尝试使用javascript提交表单时,它只提交没有发布数据值的表单!在网上搜索解决方案但无法找到解决方案!!希望有人能帮助我

代码:

 <script type="text/javascript">
      $(function() {

          $('.countdown.callback').countdown({
          date: +(new Date) + 120000,
          render: function(data) {
            $(this.el).text( this.leadingZeros(data.min, 2) + "min " + this.leadingZeros(data.sec, 2) + " sec");
            if(this.leadingZeros(data.min, 2) < 01 && this.leadingZeros(data.sec, 2) <=  10){
                 $(this.el).addClass('ended');
                }
          },
          onEnd: function() {

              document.getElementById('myform').submit();


          }
        });

       });

</script>

使用php的HTML代码

<?php 
   foreach($row as $r){

       if(!empty($r['question'])){

?>    
 <form   method="post" id="myform" action="subanswer.php" >

<p><span style="color:rgb(33,79,157);"><?php echo  $r['id'];?> <?php echo  $r['question'];?></span><br />

<input type="radio" name="<?php echo $r['test_id'].'_'.$r['id'];?>"  value="<?php echo $r['ans1'];?>">  <?php echo $r['ans1'];?>
<br>
<input type="radio" name="<?php echo $r['test_id'].'_'.$r['id'];?>" value="<?php echo $r['ans2'];?>">  <?php echo $r['ans2'];?>
<br>
<input type="radio" name="<?php echo $r['test_id'].'_'.$r['id'];?>" value="<?php echo $r['ans3'];?>">   <?php echo $r['ans3'];?>

<input type="hidden" name="testname" value="<?php echo $_GET['id']?>">

</p>
<?php
       }
       }
?>


  <input type="submit" name="subans" value="add"  class="but" style="width:15%;" />

</form> 

1 个答案:

答案 0 :(得分:0)

从您的代码中,您似乎正在调用错误的表单:

document.getElementById('myForm').submit();

ID myFom不存在。你有:

<form method="post" id="myform1" action="subanswer.php" >

也不确定为什么人们不会始终坚持使用JQuery。建议:

$("#myForm1").submit();