0

I'm trying to make a get request through jQuery from localhost (NodeJS) the get request works as expected when I check it with Postman, I should get json like this:

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

When I run the code, the alert box doesn't show up, I able to get data from other url's which aren't localhost so I don't know what is wrong.

Hope you can help, here is my code:

<!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>
zb22
  • 3,126
  • 3
  • 19
  • 34
  • In your browser's debugging tools, is the AJAX request made? What is the server's response? – David Apr 22 '17 at 22:08
  • Have you checked your firewall settings? Sometimes your virus program blocks your calls (especially Avast)... – nicost Apr 22 '17 at 22:34
  • install a `cors` package. Also start using error handling...it's there just for this purpose. SHould also have seen cors warnings in console – charlietfl Apr 22 '17 at 23:22
  • I tried to add 'https://crossorigin.me' in the beginning of the url and still doesn't work – zb22 Apr 23 '17 at 11:33

0 Answers0