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);


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM