php ajax dom---动态增加
Posted 两只小蜜蜂啊
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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\"> </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\"> </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."\"}"; ?>
以上是关于php ajax dom---动态增加的主要内容,如果未能解决你的问题,请参考以下文章