2012-05-09 37 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瀏覽器)的頂部的黑點按鈕。這將保留頁面加載之間的日誌消息。

相關問題