我正在从本地计算机使用伪造的json并将其托管在json服务器上。这是我的CLI ...
GET /posts 200 19.549 ms - 77
GET /posts 304 15.604 ms - -
GET /posts 304 6.905 ms - -
GET /posts 304 8.686 ms - -
GET /posts 304 11.422 ms - -
GET /posts 304 5.440 ms - -
GET /posts 304 6.910 ms - -
GET /posts 304 6.818 ms - -
当我在chrome中测试我的网址(第一个请求)成功并显示...
"id": 1,
"title": "json-server"
"author": "typicode"
当我尝试在Js小提琴的代码段中执行请求时,收到:
ID: Undefined
Title: Undefined
Author: Undefined
为什么会这样?
<button>Search</button>
$(document).ready(function(){
$("button").click(function(){
$.get("http://localhost:3000/posts", function(id, title, author){
alert("ID: " + id.id + "\nTitle: " + title.title + "\nAuthor: " +
author.author);
});
});
});