ajax请求html内容

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>看新闻</title>
</head>
<body>
<input type="button" value="看新闻">
<ul></ul>
</body>
<script type="text/javascript">
document.getElementsByTagName('input')[0].onclick=function(){
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(){
if(this.readyState==4){
document.getElementsByTagName('ul')[0].innerHTML = this.responseText;
}

}
xhr.open('get','07.php',true);

xhr.send(null);
};
</script>
</html>

 

 

<?php

$news = array(
array(
'id'=>1,
'title'=>'天气好',
),
array(
'id'=>2,
'title'=>'天气dzc好',
),
array(
'id'=>3,
'title'=>'天气dsja好ds',
),
);

foreach($news as $n){
echo '<li><a href="news.php?id="',$n['id'].'>';
echo $n['title'];
echo '</a></li>';
}
// echo json_encode($news);

posted @ 2019-06-14 08:40  yahn~  阅读(3026)  评论(0编辑  收藏  举报