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