JQuery应用实例学习 —— 29 处理json返回值,点击出现后台返回数据

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/dyw_666666/article/details/82764214

27.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>jQuery处理ajax的json返回值</title>
</head>
<body>
    <input type="button" value="看新闻">
    <ul>
        <li></li>
        <li></li>
        <li></li>
    </ul>
</body>
<script src="jquery.js"></script>
<script>

// 点击出现后台返回数据
$('input').click(function(){
    $.get('27.php' , function(msg){ // msg回调函数
        var i = 0;
        $('li').each(function(){ // 用面向函数的思想遍历
            this.innerHTML = msg[i++];
        });
    } , 'json');
});

</script>
</html>

27.php

<?php 

$news = array(
'郭美美被抓',
'云南地震',
'新疆反恐'
);
echo json_encode($news);

?>

 

猜你喜欢

转载自blog.csdn.net/dyw_666666/article/details/82764214