Php 在其他页面的特定div中发布数据

Php 在其他页面的特定div中发布数据,php,jquery,html,Php,Jquery,Html,我想知道我是否可以将表单中的数据发布到另一页上的特定div。比如说, form.php <?php if(isset($_POST['budget'])){ $budget=$_POST['budget']; $paid=$_POST['paid']; $ammount=$_POST['ammount']; $gst=$_POST['gst']; } $total=$budget+$paid+$ammount+$gst; echo $total; ?>

我想知道我是否可以
将表单中的数据发布到另一页上的特定div。比如说,

form.php

<?php
if(isset($_POST['budget'])){
    $budget=$_POST['budget'];
    $paid=$_POST['paid'];
    $ammount=$_POST['ammount'];
    $gst=$_POST['gst']; 
}
$total=$budget+$paid+$ammount+$gst;
echo $total;
?>

<div id="content">
<?php
if(isset($_POST['hod'])){
    $hod=$_POST['hod'];
}
require '../db_connection/connection-intra.php';
$sql="SELECT s.nama,s.staff_id,gp.jawatan,j.nama_jabatan from staff s INNER JOIN gred_pekerja gp ON s.gred_id=gp.gred_id INNER JOIN jabatan j ON j.j_id=s.j_id WHERE s.staff_id='$hod'";
$result=mysqli_query($conn, $sql);
if(!$result) {
    die(mysqli_error($conn));
} 
if(mysqli_num_rows($result) > 0){
    while($row=mysqli_fetch_assoc($result)){
        $jawatan=$row['jawatan'];
        $jabatan=$row['nama_jabatan'];
    }
}
mysqli_free_result($result);
mysqli_close($conn);
echo $jawatan." ".$jabatan;
?>
</div>
我在jQuery中有以下代码:

$("#hod").change(function(){
        var hod = $('#hod').val();
        $.post('calc.php #content',
        {
            hod : hod
        }, function(data){
            $('#designation').html(data)
        });
    });
calc.php

<?php
if(isset($_POST['budget'])){
    $budget=$_POST['budget'];
    $paid=$_POST['paid'];
    $ammount=$_POST['ammount'];
    $gst=$_POST['gst']; 
}
$total=$budget+$paid+$ammount+$gst;
echo $total;
?>

<div id="content">
<?php
if(isset($_POST['hod'])){
    $hod=$_POST['hod'];
}
require '../db_connection/connection-intra.php';
$sql="SELECT s.nama,s.staff_id,gp.jawatan,j.nama_jabatan from staff s INNER JOIN gred_pekerja gp ON s.gred_id=gp.gred_id INNER JOIN jabatan j ON j.j_id=s.j_id WHERE s.staff_id='$hod'";
$result=mysqli_query($conn, $sql);
if(!$result) {
    die(mysqli_error($conn));
} 
if(mysqli_num_rows($result) > 0){
    while($row=mysqli_fetch_assoc($result)){
        $jawatan=$row['jawatan'];
        $jabatan=$row['nama_jabatan'];
    }
}
mysqli_free_result($result);
mysqli_close($conn);
echo $jawatan." ".$jabatan;
?>
</div>


如果我将
post
值发送到pagecalc.php,它还将获取
之外的值。是否有办法只发送

上的内容,其中
#hod
?您可以在
calc.php
上使用
strip_tags()
。问题是您返回的文档本身不是有效的HTML文档,因此您可能无法解析它以便仅提取内容div。可能会触发Zalgo的愤怒,您是否考虑过使用正则表达式来提取该块?如果您不想在
div
之外显示值,请不要在它之前或之后显示任何内容。感谢提供详细信息。将在
#hod
的位置尝试?您可以在
calc.php
上使用
strip_tags()
。问题是您返回的文档本身不是有效的HTML文档,因此您可能无法解析它以便仅提取内容div。可能会触发Zalgo的愤怒,您是否考虑过使用正则表达式来提取该块?如果您不想在
div
之外显示值,请不要在它之前或之后显示任何内容。感谢提供详细信息。我会试试的