这个怎么用Ajax提取出来写成html?

这个怎么用Ajax提取出来写成html?,第1张

<dl id="output"></dl>

<script>

$.ajax({

url:略,

success:function(res){

var html=""

res.article.forEach(function(e){

html+="<dt>"+e.title+"</dt>"

html+="<dd>"+e.content

if(e.images)e.images.forEach(ee){

html+="<img src='"+ee+"'/>"

}

html+="</dd>"

})

$("#output").append(html)

}

})

</script>

$(function(){

var comments = $("#comments")

$.getJSON("server.php",function(json){

$.each(json,function(index,array){

var txt = "<p><strong>"+array["user"]+"</strong>:"+array["comment"]+"<span>"

+array["addtime"]+"</span></p>"

comments.append(txt)

})

})

$("#add").click(function(){

var user = $("#user").val()

var txt = $("#txt").val()

$.ajax({

type:'POST',

url:"comment.php",

data:"user="+user+"&txt="+txt,

success:function(msg){

if(msg==1){

var str = "<p><strong>"+user+"</strong>:"+txt+"<span>刚刚</span></p>"

comments.append(str)

$("#message").show().html("发表成功!").fadeOut(1000)

$("#txt").attr("value","")

}else{

$("#message").show().html(msg).fadeOut(2000)

}

}

})

})

})


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/6099850.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-14
下一篇 2023-03-14

发表评论

登录后才能评论

评论列表(0条)

保存