求大神,ajax怎么获取php文件里的数组并输出? 50
是这样的,我有一个1.php,里面是["3","萌新5367","萌新613","萌新213",],我想把3输出到renshu,把后面不确定数量的名字分别输出到ren的u...
是这样的,我有一个1.php,里面是["3","萌新5367","萌新613","萌新213",],
我想把3输出到renshu,把后面不确定数量的名字分别输出到ren的ul里面成<li>,
下面的代码是不行的,请问到底要怎么写?谢谢大神
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="jquery.min.js"></script>
</head>
<body>
<div class="renshu"></div>
<div class="ren"><ul></ul></div>
<script>
$.ajax({
url: "1.php",
type: 'GET',
success: function(data) {
var value = data;var count = parseInt(value[0]);$(".renshu").append(count);
var list = $(".ren ul");
for(var i=1;i<=count;i++){
list.append("<li>"+value[i]+"</li>");
}
},
beforeSend: function(xhr) {
xhr.setRequestHeader("Cache-Control", "no-cache");
},
async: true,
});
</script>
</body>
</html> 展开
我想把3输出到renshu,把后面不确定数量的名字分别输出到ren的ul里面成<li>,
下面的代码是不行的,请问到底要怎么写?谢谢大神
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="jquery.min.js"></script>
</head>
<body>
<div class="renshu"></div>
<div class="ren"><ul></ul></div>
<script>
$.ajax({
url: "1.php",
type: 'GET',
success: function(data) {
var value = data;var count = parseInt(value[0]);$(".renshu").append(count);
var list = $(".ren ul");
for(var i=1;i<=count;i++){
list.append("<li>"+value[i]+"</li>");
}
},
beforeSend: function(xhr) {
xhr.setRequestHeader("Cache-Control", "no-cache");
},
async: true,
});
</script>
</body>
</html> 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询