donglisi8644 2012-07-06 22:20
浏览 27
已采纳

Form的$ .post出错

I am trying to submit a form using JQuery to a PHP page. But I get the following error when I try to run the script from Chrome:

    Uncaught SyntaxError: Unexpected token ;       jquery-latest.js;614

Line 614 is part of the GlobalEval function.

globalEval: function( data ) {
    if ( data && rnotwhite.test( data ) ) {
        // We use execScript on Internet Explorer
        // We use an anonymous function so that context is window
        // rather than jQuery in Firefox
        ( window.execScript || function( data ) {
            window[ "eval" ].call( window, data );
// **** Uncaught SyntaxError: Unexpected token ; **** //
        } )( data );
    }
},

This is my code for my form and JQuery submit.

<div class="container create-event">
  <form name="new-event" method="post" id="new-event">
    Name of the event: <input type="text" name="event-name"></br>
    Date of the event: <input type="date" name="date"></br>
    Location of the event: <input type="text" name="location"></br>
    Description: <textarea cols="50" rows="5" name="description"></textarea></br>
    <a href="#" id="event-submit" class="button red">Submit</a>
    <script type="text/javascript">
      $('#new-event').submit(function() {
        $.post(
          'post-event.php',
          $(this).serialize(),
          function(data){
            $('#results').html(data);
          }
        );
        return false;
      });
      $('#event-submit').click(
        $(this).parents('form:first').submit();
      );
    </script>
  </form>
  <div id="results"></div>
</div>

Then my 'post-event.php' script is this:

<?php
echo "Hello";
?>

Any help is much appreciated.

  • 写回答

1条回答 默认 最新

  • dqfsbvd43312 2012-07-06 22:31
    关注
    $('#event-submit').click(
        $(this).parents('form:first').submit();
     );
    

    After changing the click function into the code below it worked for me.

    $('#event-submit').click(function(){
        $(this).parents('form:first').submit();
    });
    

    You were missing the function() reference.

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

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料