Javascript 发生错误时出现意外标识符
我有一个意外的代码错误,但我无法识别它 代码:Javascript 发生错误时出现意外标识符,javascript,php,Javascript,Php,我有一个意外的代码错误,但我无法识别它 代码: $('#add1')。单击(函数(){ var html=''; html+=''; html+=''; html+=''; html+=''; html+=''; html+=''; }); 在我的角色中,此回显线路出现意外错误: echo "<option value=".$ln['nome'].">".$ln['nome']."</option>"; echo“$ln['nome']”; 完整代码: $(docu
$('#add1')。单击(函数(){
var html='';
html+='';
html+='';
html+='';
html+='';
html+='';
html+='';
});
在我的角色中,此回显线路出现意外错误:
echo "<option value=".$ln['nome'].">".$ln['nome']."</option>";
echo“$ln['nome']”;
完整代码:
$(document).ready(function(){
dom: 'Bflrtip',
fetch_data();
function fetch_data()
{
var dataTable = $('#user_data').DataTable({
dom: 'Bflrtip',
"processing" : true,
"serverSide" : true,
"pagingType": "full_numbers",
"iDisplayLength": 5,
"oLanguage": {
"sProcessing": "Aguarde enquanto os dados são carregados ...",
"sLengthMenu": "Mostrar _MENU_ registos por página",
"sZeroRecords": "Nenhum registo correspondente ao criterio encontrado",
"sInfoEmtpy": "Exibindo 0 a 0 de 0 registos",
"sInfo": "Exibindo de _START_ a _END_ de _TOTAL_ registos",
"sInfoFiltered": "",
"sSearch": "<span class='glyphicon glyphicon-search'></span>",
"oPaginate": {
"sFirst": "<span class='glyphicon glyphicon-fast-backward'></span>",
"sPrevious": "<span class='glyphicon glyphicon-backward'></span>",
"sNext": "<span class='glyphicon glyphicon-forward'></span>",
"sLast": "<span class='glyphicon glyphicon-fast-forward'></span>"
}
},
buttons: [
{
extend: 'excel',
text: 'excel',
title: 'Consultas Semanais',
},
{
extend: 'pdf',
text: 'pdf',
title: 'Consultas Semanais',
},
{
extend: 'print',
text: 'print',
title: 'Consultas Semanais',
customize: function ( win ) {
$(win.document.body)
.css( 'font-size', '10pt' );
$(win.document.body).find( 'table' )
.addClass( 'compact' )
.css( 'font-size', 'inherit' );
}
}
],
"order" : [],
"ajax" : {
url:"./fetchconsulta",
type:"POST"
}
});
}
function update_data(id, column_name, value)
{
$.ajax({
url:"./updateconsulta",
method:"POST",
data:{id:id, column_name:column_name, value:value},
success:function(data)
{
$('#alert_message').html('<div class="alert alert-success">'+data+'</div>');
}
});
setInterval(function(){
$('#alert_message').html('');
}, 5000);
}
$(document).on('blur', '.update', function(){
var id = $(this).data("id");
var column_name = $(this).data("column");
var value = $(this).text();
update_data(id, column_name, value);
});
var semana = ["Domingo", "Segunda-Feira", "Terça-Feira", "Quarta-Feira", "Quinta-Feira", "Sexta-Feira", "Sábado"];
$('#add1').click(function(){
var html = '<tr>';
html += '<td contenteditable ><input type="date" class="input-date" id="data1"/></td>';
html += '<td contenteditable><input type="text" class="input-day" id="data2"/></td>';
html += '<td contenteditable ><input type="time" id="data3"/></td>';
html += '<td contenteditable><input type="time" id="data4"/></td>';
html += '<td contenteditable><select id="data5"><option></option><?php
$sql = "SELECT nome FROM raddb.Utente ORDER BY nome ASC";
$qr = mysqli_query($conn, $sql);
while($ln = mysqli_fetch_assoc($qr)){
echo "<option value=".$ln['nome'].">".$ln['nome']."</option>";
}?></select></td>';
html += '</tr>';
});
});
$(文档).ready(函数(){
dom:'Bflrtip',
获取_数据();
函数fetch_data()
{
var dataTable=$(“#用户_数据”).dataTable({
dom:'Bflrtip',
“处理”:对,
“服务器端”:正确,
“pagingType”:“完整编号”,
“iDisplayLength”:5,
“语言”:{
“sProcessing”:“Aguarde enquanto os dados são carregados…”,
“长菜单”:“最长菜单”,
“sZeroRecords”:“Nenhum Registro通讯员和认证标准”,
“sInfoEmtpy”:“Exibindo 0 a 0 de 0 registos”,
“sInfo”:“开始、结束、总计登记”,
“Sinfofilted”:“,
“搜索”:“搜索”,
“oPaginate”:{
“第一项”:“第三项”,
“以前的”:“,
“sNext”:“,
“斜杠”:”
}
},
按钮:[
{
扩展:“excel”,
文本:“excel”,
标题:“Semanais领事馆”,
},
{
扩展:“pdf”,
文本:“pdf”,
标题:“Semanais领事馆”,
},
{
扩展:“打印”,
文本:“打印”,
标题:“Semanais领事馆”,
自定义:功能(win){
$(win.document.body)
.css('font size','10pt');
$(win.document.body).find('table')
.addClass('compact')
.css('font size','inherit');
}
}
],
“订单”:[],
“ajax”:{
url:“./fetchconsulta”,
类型:“职位”
}
});
}
函数更新数据(id、列名称、值)
{
$.ajax({
url:“./UpdateSulta”,
方法:“张贴”,
数据:{id:id,column\u name:column\u name,value:value},
成功:功能(数据)
{
$('#警报信息').html(''+数据+'');
}
});
setInterval(函数(){
$('#警报信息').html('');
}, 5000);
}
$(文档).on('blur','.update',函数(){
var id=$(this.data(“id”);
var column_name=$(此).data(“列”);
var值=$(this.text();
更新数据(id、列名称、值);
});
var semana=[“多明戈”、“塞贡达·费拉”、“特里萨·费拉”、“夸塔·费拉”、“昆塔·费拉”、“塞克斯塔·费拉”、“萨巴多”];
$('#add1')。单击(函数(){
var html='';
html+='';
html+='';
html+='';
html+='';
html+='';
html+='';
});
});
就在这一行,您有一个打开的PHP标记,但没有关闭表格单元格和代码行:
html += '<td contenteditable><select id="data5"><option></option><?php
html+='
html+='';
html+='';
但是你这里有个问题
您试图在JavaScript命令内运行PHP,但这不会起作用。如果希望保持函数“原样”,需要做的是触发对PHP的AJAX请求,并将信息返回到标记中的选项中。因此,您的代码应该是这样的:
html += '<td contenteditable><select id="data5"><option></option>';
$('#data5').load('options.php');
html += '</select></td>';
html += '</tr>';
<?php
$conn = mysqli_connect("HOST", "USER", "PW", "DATABASE");
$sql = "SELECT nome FROM raddb.Utente ORDER BY nome ASC";
$qr = mysqli_query($conn, $sql);
while($ln = mysqli_fetch_assoc($qr)){
echo "<option value=".$ln['nome'].">".$ln['nome']."</option>";
}
?>
html+='';
$('#data5').load('options.php');
html+='';
html+='';
options.php如下所示:
html += '<td contenteditable><select id="data5"><option></option>';
$('#data5').load('options.php');
html += '</select></td>';
html += '</tr>';
<?php
$conn = mysqli_connect("HOST", "USER", "PW", "DATABASE");
$sql = "SELECT nome FROM raddb.Utente ORDER BY nome ASC";
$qr = mysqli_query($conn, $sql);
while($ln = mysqli_fetch_assoc($qr)){
echo "<option value=".$ln['nome'].">".$ln['nome']."</option>";
}
?>
但是您可能会遇到时间问题,因为当AJAX从PHP返回数据时,
#data5
可能不存在,所以您必须确保在进行AJAX调用之前,#data5
存在。在这一行中,您有一个打开的PHP标记,但没有关闭表单元格和代码行:
html += '<td contenteditable><select id="data5"><option></option><?php
html+='
html+='';
html+='';
但是你这里有个问题
您试图在JavaScript命令内运行PHP,但这不会起作用。如果希望保持函数“原样”,需要做的是触发对PHP的AJAX请求,并将信息返回到标记中的选项中。因此,您的代码应该是这样的:
html += '<td contenteditable><select id="data5"><option></option>';
$('#data5').load('options.php');
html += '</select></td>';
html += '</tr>';
<?php
$conn = mysqli_connect("HOST", "USER", "PW", "DATABASE");
$sql = "SELECT nome FROM raddb.Utente ORDER BY nome ASC";
$qr = mysqli_query($conn, $sql);
while($ln = mysqli_fetch_assoc($qr)){
echo "<option value=".$ln['nome'].">".$ln['nome']."</option>";
}
?>
html+='';
$('#data5').load('options.php');
html+='';
html+='';
options.php如下所示:
html += '<td contenteditable><select id="data5"><option></option>';
$('#data5').load('options.php');
html += '</select></td>';
html += '</tr>';
<?php
$conn = mysqli_connect("HOST", "USER", "PW", "DATABASE");
$sql = "SELECT nome FROM raddb.Utente ORDER BY nome ASC";
$qr = mysqli_query($conn, $sql);
while($ln = mysqli_fetch_assoc($qr)){
echo "<option value=".$ln['nome'].">".$ln['nome']."</option>";
}
?>
但是您可能会遇到时间问题,因为当AJAX从PHP返回数据时,
#data5
可能不存在,因此您必须确保在进行AJAX调用之前,#data5
存在。您打断了多行,但没有用“\”转义新行
因此,如果要将php代码添加到html
变量中。那么你可以试试这个,,,
因此,您可以尝试添加“\”
$('#add1').click(function(){
var html = '<tr>';
html += '<td contenteditable ><input type="date" class="input-date" id="data1"/></td>';
html += '<td contenteditable><input type="text" class="input-day" id="data2"/></td>';
html += '<td contenteditable ><input type="time" id="data3"/></td>';
html += '<td contenteditable><input type="time" id="data4"/></td>';
html += '<td contenteditable><select id="data5"><option></option><?php \
$sql = "SELECT nome FROM raddb.Utente ORDER BY nome ASC"; \
$qr = mysqli_query($conn, $sql); \
while($ln = mysqli_fetch_assoc($qr)){ \
echo "<option value=".$ln[\'nome\'].">".$ln[\'nome\']."</option>"; \
}?></select></td>';
html += '</tr>';
});
$('#add1')。单击(函数(){
var html='';
html+='';
html+='';
html+='';
html+='';
html+='';
html+='';
});
或者我推荐这个,
$('#add1').click(function(){
var html = '<tr>';
html += '<td contenteditable ><input type="date" class="input-date" id="data1"/></td>';
html += '<td contenteditable><input type="text" class="input-day" id="data2"/></td>';
html += '<td contenteditable ><input type="time" id="data3"/></td>';
html += '<td contenteditable><input type="time" id="data4"/></td>';
html += `<td contenteditable><select id="data5"><option></option><?php
$sql = "SELECT nome FROM raddb.Utente ORDER BY nome ASC";
$qr = mysqli_query($conn, $sql);
while($ln = mysqli_fetch_assoc($qr)){
echo "<option value=".$ln['nome'].">".$ln['nome']."</option>";
}?></select></td>`;
html += '</tr>';
});
$('#add1')。单击(函数(){
var html='';
html+='';
html+='';
html+='';
html+='';
html+=`;
html+='';
});
但是,如果您想执行PHP代码,那么请检查您的服务器,因为它可能无法工作。如果有,那么您不应该在浏览器中获取PHP代码 否则请更准确地描述您的问题
- 你想执行PHP代码吗
- 或者,它已经被执行了
- 或者,您想在html中显示PHP代码吗
html
变量中。那么你可以试试这个,,,
因此,您可以尝试添加“\”
$('#add1').click(function(){
var html = '<tr>';
html += '<td contenteditable ><input type="date" class="input-date" id="data1"/></td>';
html += '<td contenteditable><input type="text" class="input-day" id="data2"/></td>';
html += '<td contenteditable ><input type="time" id="data3"/></td>';
html += '<td contenteditable><input type="time" id="data4"/></td>';
html += '<td contenteditable><select id="data5"><option></option><?php \
$sql = "SELECT nome FROM raddb.Utente ORDER BY nome ASC"; \
$qr = mysqli_query($conn, $sql); \
while($ln = mysqli_fetch_assoc($qr)){ \
echo "<option value=".$ln[\'nome\'].">".$ln[\'nome\']."</option>"; \
}?></select></td>';
html += '</tr>';
});
$('#add1')。单击(函数(){
var html='';
html+='';
html+='';
html+='';
html+='';
html+='';
html+='';
});
或者我推荐这个,
$('#add1').click(function(){
var html = '<tr>';
html += '<td contenteditable ><input type="date" class="input-date" id="data1"/></td>';
html += '<td contenteditable><input type="text" class="input-day" id="data2"/></td>';
html += '<td contenteditable ><input type="time" id="data3"/></td>';
html += '<td contenteditable><input type="time" id="data4"/></td>';
html += `<td contenteditable><select id="data5"><option></option><?php
$sql = "SELECT nome FROM raddb.Utente ORDER BY nome ASC";
$qr = mysqli_query($conn, $sql);
while($ln = mysqli_fetch_assoc($qr)){
echo "<option value=".$ln['nome'].">".$ln['nome']."</option>";
}?></select></td>`;
html += '</tr>';
});
$('#add1')。单击(函数(){
变量