方法一:通過(guò)本地服務(wù)器
1.通過(guò)在控制臺(tái)輸入http-server開(kāi)啟本地服務(wù)器
獲取端口號(hào)http://localhost:8000
2.然后通過(guò)在文件夾創(chuàng)建html和json文件來(lái)測(cè)試數(shù)據(jù)
示例:
//html文件
<body>
<script>
var xhr = new XMLHttpRequest()
xhr.open('GET','/hello.json',true)
xhr.send()
xhr.addEventListener('load',function(){
var date = xhr.responseText;
console.log(date)
})
</script>
//json文件
{
"name":"jirengu",
"age":"2"
}
3.打開(kāi)瀏覽器的控制臺(tái)就能看到輸出的數(shù)據(jù):

方法二:通過(guò)線(xiàn)上mock數(shù)據(jù)
以Easy Mock為例,進(jìn)入網(wǎng)站后建立個(gè)人項(xiàng)目,進(jìn)入項(xiàng)目后可創(chuàng)建接口并查看。

創(chuàng)建接口

查看接口