2017-08-30 80 views
0

我有一個帶有div容器的索引頁面。 我在頁面上create_node_group.php 我加載正在加載幷包含窗體的索引頁div容器中的creating_node_group。 當我提交表單沒有任何反應。提交無效

我的.js是

$("#create_node_group").submit(function() { // catch the form's submit 
    alert("submit called"); 

    $.ajax({ // create an AJAX call... 
     data: $(this).serialize(), // get the form data 
     type: $(this).attr('method'), // GET or POST 
     url: $(this).attr('action'), // the file to call 
     success: function(response) { // on success.. 
      $('#content').html(response); // update the DIV 

     } 
    }); 

這是我的create_node_group其正確加載索引頁div容器。當我提交表單時沒有任何反應。

<?php 
include "db.php"; 
$query = "select * from monitor_template"; 
$template = array(); 
$row_num; 
$result=pg_query($conn, $query); 
    if (!$result) { 
    echo "query did not execute"; 
    } 
    if (pg_num_rows($result) == 0) { 
    echo "0 records"; 
    } 
    else { 
     $a=0; 
    while ($row = pg_fetch_array($result)) { 
    //do stuff with $row 
    $template[$a][0]=$row[mon_template_id]; 
    $template[$a][1]=$row[template_name]; 
    $a=$a+1; 
    } 
    } 
$row_num=pg_num_rows($result); //row count starts from 0 
//echo 'rows returned are: '.$row_num; 
//print_r($template); 
//echo $template[0][0].'-'.$template[0][1].'--'.$template[1][0].'-'.$template[1][1]; 
?> 
<table> 
<form class="content_form" id="create_node_group" name = "create_node_group" action="process_create_node_group.php" method="post"> 
<tr><td> 
Node Group Path: </td> <td><input type="text" name="path"></td></tr> 

<tr><td> 
Node Group ID: </td><td><input type="text" name="node_group_id" disabled="disabled"></td></tr> 

<tr><td> 
Node Group Name:</td> <td> <input type="text" name="node_group_name"></td></tr> 


<?php 
for($i=1;$i<=5;$i++) 
{ 
echo '<tr><td>'; 
echo 'Monitoring Template '. $i.':</td><td> <select id="Mon_template'.$i.'" name="Mon_template'.$i.'">'; 
echo ' <option value="">Select</option>'; 
for($j=0;$j<$row_num;$j++) 
{ 
    echo '<option value="'.$template[$j][0].'">'.$template[$j][1].'</option>'; 
} 
echo '</select >'; 
echo '</td></tr>'; 

} 
?> 
<tr><td colspan="2"> 
<input type="submit" value="Submit" > 
</td></tr> 
</form> 
</table> 
+1

請,(HTTP [使用'警報()'進行故障排除退出。]: //stravid.com/en/stop-the-javascript-alert-madness/),請改用'console.log()'。 –

+0

[你看過瀏覽器開發工具中的AJAX請求/響應了嗎?你有沒有在項目中包含jQuery庫?是否有任何錯誤報告?你在網絡服務器上運行它嗎?](http://jayblanchard.net/basics_of_jquery_ajax.html) –

回答

1

因爲您正在加載通過AJAX的形式我認爲,這是因爲你的表格是不是住嘗試

$(document).on('submit','#create_node_group'(function() { // catch the form's submit 
alert("submit called"); 

$.ajax({ // create an AJAX call... 
    data: $(this).serialize(), // get the form data 
    type: $(this).attr('method'), // GET or POST 
    url: $(this).attr('action'), // the file to call 
    success: function(response) { // on success.. 
     $('#content').html(response); // update the DIV 

    } 
});