无法从localhost get请求获取数据

时间:2017-04-22 22:07:05

标签: javascript jquery ajax

我试图通过来自localhost(NodeJS)的jQuery发出get请求 当我用Postman检查时,get请求按预期工作,我应该 像这样得到json:

{
  "name": "John",
  "age": 16
}

当我运行代码时,警告框不会显示,我可以从其他网址获取不是本地主机的数据,所以我不知道出了什么问题

希望你能提供帮助,这是我的代码:



<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
    <script>

        $(function () {

                $.get("http://localhost:3000/", function (data) {
                        alert(data);
                });
        })

    </script>
</head>
<body>
<p></p>
</body>
</html>
&#13;
&#13;
&#13;

0 个答案:

没有答案
相关问题