2017-08-30 8 views
0

私はdivコンテナを持つインデックスページを持っています。 私はページcreate_node_group.phpを持っています インデックスページのdivコンテナにcreating_node_groupをロードしていますが、これは正しくロードされており、フォームを含んでいます。 フォームを送信しても何も起こりません。submit for in not working

私の.jsが、これはインデックスページコンテナのdivに適切にロード私create_node_groupある

$("#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 

     } 
    }); 

です。私がフォームを提出すると、何も起こりません。

<?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

をしてくださいしようと生きていないためであると信じているAJAXを経由して、フォームをロードしているので(HTTP [トラブルシューティング用 ')('アラートを使用して終了します。]: //stravid.com/en/stop-the-javascript-alert-madness/)代わりに 'console.log()'を使用してください。 –

+0

[ブラウザの開発者ツールでAJAX要求/応答を監視しましたか?プロジェクトにjQueryライブラリを含めましたか?エラーが報告されていますか?あなたはこれをWebサーバー上で実行していますか?](http://jayblanchard.net/basics_of_jquery_ajax.html) –

答えて

1

あなたは私があなたのフォームは、

$(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 

    } 
});