php ajax dom---动态增加

js代码

<script type="text/javascript">
$(document).ready(function(){
  $("#talk_send").click(function(){
    
    var ask = $("#ask").val();
    
    $.ajax({
             type: "GET",
             url: "action.php",
             data: {value:ask},
             dataType: "json",
             success: function(data){
                        $('#jp-container').append('<div class=\"talk_recordbox\"><div class=\"user\"><img src=\"images/thumbs/11.jpg\"/>刘韵</div><div class=\"talk_recordtextbg\">&nbsp;</div><div class=\"talk_recordtext\"><h3 >我的问题是:<label class=\"huida\">'+data['ask']+'</label></h3><span class=\"talk_time\">'+data['time']+'</span></div></div>');

                        $('#jp-container').append('<div class=\"talk_recordboxme\"><div class=\"user\"><img src=\"images/thumbs/15.jpg\"/>王玉山</div><div class=\"talk_recordtextbg\">&nbsp;</div><div class=\"talk_recordtext\"><h3>对方的回答是:<label class=\"tiwen\">123</label></h3><span class=\"talk_time\">'+data['time']+'</span></div></div>');
        
                        $('#talk_record').scrollTop($('#talk_record')[0].scrollHeight);
                      }
         });
   


    
  });
});
</script>

后台程序

<?php
header("Content-Type: text/html;charset=utf-8");
$ask = $_REQUEST['value'];
$time = date("Y-m-d H:i:s");
echo "{\"time\":\"".$time."\",\"ask\":\"".$ask."\"}";
?>

 

posted @ 2016-03-30 18:42  fleam  阅读(236)  评论(0编辑  收藏  举报