ajax html返回

来源:互联网 发布:金牛考勤软件 编辑:程序博客网 时间:2024/06/16 00:09

html代码

<!doctype html><html lang="en"><head>    <meta charset="UTF-8">    <title>Document</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','1.php',true);        xhr.send(null);    }</script></html>

php代码

<?php$news = array(    array('id'=>1,'title'=>'第一条数据'),    array('id'=>2,'title'=>'第二条数据'),    array('id'=>3,'title'=>'第三条数据'),    );foreach ($news as $n) {    echo '<li><a href="news.php?id="',$n['id'],'>';    echo $n['title'];    echo '</a></li>';}?>
0 0
原创粉丝点击