Javascript-код не работает сразу после добавления PHP
У меня есть функция javascript, которая добавляет div-ы нажатием кнопки, код прекрасно работает без PHP, но как только его вставят в следующий PHP-кодкод, это больше не работает.Пожалуйста, помогите, спасибо!
<script>$(document).ready(function(){
var i=1;
$('#add').click(function(){
i++;
$('#dynamic_field').append('<tr id="row'+i+'"><td>Kategorie<br><select>"<?php while($row = mysqli_fetch_array($result)){echo '<option name="Kategoriename">' .$row['Kategorienname']. "</option>"; }?>"</select></td></select></td><td>Name<input type="text" name="name[]" placeholder="Enter your Name" class="form-control name_list" /></td><td>Inhalt<input type="text" name="name[]" placeholder="Enter your Name" class="form-control name_list" /></td><td>Preis<input type="text" name="name[]" placeholder="Enter your Name" class="form-control name_list" /></td><td>normal<input type="text" name="name[]" placeholder="Ø" class="form-control name_list" /></td><td>Preis<input type="text" name="name[]" placeholder="Enter your Name" class="form-control name_list" /></td><td>mittel<input type="text" name="name[]" placeholder="Ø" class="form-control name_list" /></td><td>Preis<input type="text" name="name[]" placeholder="Enter your Name" class="form-control name_list" /></td><td>groß<input type="text" name="name[]" placeholder="Ø" class="form-control name_list" /></td><td>Preis<input type="text" name="name[]" placeholder="Enter your Name" class="form-control name_list" /></td><td>Allergene<br><input type="checkbox" name="leer" value="leer"><img style="height:20px; width:20px;" src="../AuswahlIcon/allergene/a.png"><input type="checkbox" name="leer" value="leer"><img style="height:20px; width:20px;" src="../AuswahlIcon/allergene/b.png"><input type="checkbox" name="leer" value="leer"><img style="height:20px; width:20px;" src="../AuswahlIcon/allergene/c.png"><input type="checkbox" name="leer" value="leer"><img style="height:20px; width:20px;" src="../AuswahlIcon/allergene/d.png"><input type="checkbox" name="leer" value="leer"><img style="height:20px; width:20px;" src="../AuswahlIcon/allergene/e.png"><input type="checkbox" name="leer" value="leer"><img style="height:20px; width:20px;" src="../AuswahlIcon/allergene/f.png"><input type="checkbox" name="leer" value="leer"><img style="height:20px; width:20px;" src="../AuswahlIcon/allergene/g.png"><input type="checkbox" name="leer" value="leer"><img style="height:20px; width:20px;" src="../AuswahlIcon/allergene/h.png"><input type="checkbox" name="leer" value="leer"><img style="height:20px; width:20px;" src="../AuswahlIcon/allergene/l.png"><input type="checkbox" name="leer" value="leer"><img style="height:20px; width:20px;" src="../AuswahlIcon/allergene/m.png"><input type="checkbox" name="leer" value="leer"><img style="height:20px; width:20px;" src="../AuswahlIcon/allergene/n.png"><input type="checkbox" name="leer" value="leer"><img style="height:20px; width:20px;" src="../AuswahlIcon/allergene/o.png"><input type="checkbox" name="leer" value="leer"><img style="height:20px; width:20px;" src="../AuswahlIcon/allergene/p.png"><input type="checkbox" name="leer" value="leer"><img style="height:20px; width:20px;" src="../AuswahlIcon/allergene/r.png"></td><td><button type="button" name="remove" id="'+i+'" class="btn btn-danger btn_remove">X</button></td></tr>');
});
$(document).on('click', '.btn_remove', function(){
var button_id = $(this).attr("id");
$('#row'+button_id+'').remove();
});
$('#submit').click(function(){
$.ajax({
url:"name2.php",
method:"POST",
data:$('#add_name').serialize(),
success:function(data)
{
alert(data);
$('#add_name')[0].reset();
}
});
});
});