新手问题:ajax与json如何从服务器上获取JSON数据?

我第一次写的AJAX与JSON方法,有点不懂怎么弄的呢,恳请各位老师帮忙说解,由于什么原因出错的?

<!DOCTYPE html>

<html>

<head>

<script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>

<script>

    $(function () {

        $("button").click(function(){

            $.ajax({

                url:"http://www.tutorialspoint.com/json/data.json",

                type:"POST",

                dataType: "json",

                success:function(data){

                    $("#name").html(data.name);

                    $("#country").html(data.country);

                },

                error: function (err) {

                    console.log(err)

                }

            });

        })

    });

</script>

<title>tutorialspoint.com JSON</title>

</head>

<body>

<h1>Cricketer Details</h1>

<table class="src">

<tr><th>Name</th><th>Country</th></tr>

<tr><td><div id="name">Sachin</div></td>

<td><div id="country">India</div></td></tr>

</table>

<div class="central">

<button type="button">Update Details </button>

</body>

</html>


Helenr
浏览 563回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript