在jquery函数中回显PHP值


Echo PHP value inside a jquery Function

我正试图将php echo值分配给由jquery函数生成的输入。但到目前为止没有运气。它会中断函数,并且不会随输入字段一起显示任何结果。这个场景在查询函数中显示php值的正确方式是什么。

PHP

$tablename      = "table";
$next_increment     = 0;
//$qShowStatus        = "SHOW TABLE STATUS LIKE '$tablename'";
$qShowStatusResult  = $db_con->prepare("SHOW TABLE STATUS LIKE '$tablename'");
$qShowStatusResult->execute();
$results = $qShowStatusResult->fetchAll('PDO::FETCH_ASSOC);
foreach($results as $value){
$next_increment = $value['Auto_increment'];
}

var nextAutoIncrement = '"'<?php echo $next_increment; ?>'"';

Jquery

newSection.children(':nth-child(1)').children(':first').attr('id', 'auto_id_' + newNum).attr('name', 'auto_id_' + newNum).val(nextAutoIncrement).hide();   

试试这个

  <script language="javascript" type="text/javascript">
    var nextAutoIncrement = '<?php echo $next_increment;?>';
  </script>   

这样尝试:

<script language="javascript" type="text/javascript"
var nextAutoIncrement = <?php echo $next_increment; ?>;
</script>
<script>
//if it is anumber
var nextAutoIncrement = <?php echo $next_increment; ?>;
// if ity is a string
var nextAutoIncrement = '<?php echo $next_increment;?>';
</script>

在JS代码中需要定义<script>标签:

$tablename      = "table";
$next_increment     = 0;
$qShowStatusResult  = $db_con->prepare("SHOW TABLE STATUS LIKE '$tablename'");
$qShowStatusResult->execute();
$results = $qShowStatusResult->fetchAll('PDO::FETCH_ASSOC);
foreach($results as $value){
    $next_increment = $value['Auto_increment'];
}
<script type="text/javascript" >
var nextAutoIncrement = '<?php echo $next_increment; ?>';
</script>