du532861657 2019-06-28 03:35
浏览 36
已采纳

无法在单独的Div中拆分Ajax响应

I am trying to split the Ajax response in two separate Div. I am getting the response in a single Div. Please see the code

$(document).ready(function() {
  $.post("check.php", {
      job: exactdatainner,
      attrb: getattr
    },
    function(data, status) {
      alert("Data: " + data + "
Status: " + status);

      var obj = data.split('||');
      $(".job").html(obj[0]);
      $(".attribute").html(obj[1]);
    });
});
<div class="job"></div>
<div class="attribute"></div>



<?php
    $job = $_POST['job'];
    $attrb = $_POST['attrb'];
    echo $job;
    echo $attrb;
    ?>

I am getting the result but all the result printing inside first div only Here is the PHP code

</div>
  • 写回答

2条回答 默认 最新

  • dongpeng7744 2019-06-28 03:39
    关注

    You need to echo out the PHP logic where you want it to appear on the page:

    <?php
    $job = $_POST['job'];
    $attrb = $_POST['attrb'];
    ?>
    
    <div class="job"><?php echo $job; ?></div>
    <div class="attribute"><?php echo $attrb; ?></div>
    

    Or alternatively you can echo out the HTML components as well:

    <?php
    $job = $_POST['job'];
    $attrb = $_POST['attrb'];
    echo "<div class='job'>$job</div>";
    echo "<div class='attribute'>$attrb</div>";
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置