2012-05-09 30 views
1

我试图通过jQuery发布表单.post(),而且它不能正常工作。我没有从控制台中获得任何东西,而且非常令人沮丧。向有经验的JS用户请求帮助。非常感谢您的帮助!通过jQuery发布表单 - 没有控制台错误

NOTE:这个表格是用CodeIgniter构建的,并且使用Form Helper和HTML常规路由完美地发布。 JS/jQuery方法不能正常工作。

表:

<form class="nice custom" id="create_form"> 

        <h3>Create Event</h3> 

        <label for="intention"><strong>Intention:</strong></label> 
        <?php $intention_attributes='style="width: 100%; " class="show-on-phones" id="intention_dropdown"'; ?> 
        <?php echo form_dropdown('intention', $intention, 'Select Intention', $intention_attributes); ?> 
        <div class="custom dropdown show-on-desktops" style="width: 100%; "> 
         <a href="#" class="current">Select Intention</a> 
         <a href="#" class="selector"></a> 
         <ul style="width: 100%; "> 
          <li>Select Intention</li> 
          <li>Option 1</li> 
          <li>Option 2</li> 
          <li>Option 3</li> 
          <li>Option 4</li> 
          <li>Option 5</li> 
         </ul> 
        </div> 

        <label for="action"><strong>Action:</strong></label> 
        <?php echo form_input($action); ?> 

        <label for="date_of_event"><strong>Date:</strong></label> 
        <?php echo form_input($date_of_event); ?> 

        <label for="repeat_event"><strong>Repeat:</strong></label> 
        <?php $repeat_event_attributes='style="width: 100%; " class="show-on-phones" id="repeat_event_dropdown"'; ?> 
        <?php echo form_dropdown('repeat_event', $repeat_event, 'Never', $repeat_event_attributes); ?> 
        <div class="custom dropdown show-on-desktops" style="width: 100%; "> 
         <a href="#" class="current">Never</a> 
         <a href="#" class="selector"></a> 
         <ul style="width: 100%; "> 
          <li>Never</li> 
          <li>Every Day</li> 
          <li>Every Week</li> 
          <li>Every Two Weeks</li> 
          <li>Every Month</li> 
          <li>Every year</li> 
         </ul> 
        </div> 

        <label for="end_repeat_event"><strong>End Repeat:</strong></label> 
        <?php echo form_input($end_repeat_event); ?> 

        <br /> 

        <input style="width: 100%; " type="submit" name="submit" class="medium radius blue button" value="Create" id="create_button" /> 
</form> 

的JavaScript:

// Submit Create Form 
    $('#create_form').live('submit', function() { 
     var data = $('#create_form').serialize(); 
     var url = $(this).attr('action'); 
     $.post(url, data, function() { 
      document.location.reload(); 
     }); 
     return false; 
    }); // End 
+0

什么是“不工作”?如果您观看网络流量(例如使用IE9开发人员工具等),您是否看到通过线路发送的请求?该请求的HTTP响应代码是什么? –

+0

你的'

'没有'action'。我不记得''this'如何在你的声明中解析:'var url = $(this).attr('action');'也许明确地添加动作会解决它。 – Andrew

+1

向我们展示PHP处理后存在的表单更有帮助。 – Sampson

回答

1

你的表单没有动作值:

<form class="nice custom" id="create_form"> 

即使你试图得到一个:

var url = $(this).attr('action'); 

此外,避免在使用了从$.live这里:

在jQuery 1.7的,所述方法.live()不推荐使用。使用.on()附加事件处理程序。旧版本jQuery的用户应优先使用.delegate()而不是.live()

http://api.jquery.com/live/

+0

感谢您关于'.live()'和'.on()'的提示。我将从这里开始实施。我将删除'.attr('action');看看是否解决了这个问题。它来自表单的较旧版本。 – imlouisrussell

+0

我在你的帮助下解决了这个问题。非常感谢你! – imlouisrussell

0

试着改变你的提交按钮btnSubmit按钮的名称。我以前遇到了提交按钮提交的问题。

谢谢,

0

另外,按下控制台输出标签(WebKit浏览器)的顶部的黑点按钮。这将保留页面加载之间的日志消息。

相关问题