0

I'm running a very simple http server (following this: https://gist.github.com/bradmontgomery/2219997) in python on my system.

I then wrote a basic ajax code to send GET or POST http requests to this server. But even a simple GET request is failing and only the failure handler is hit each time. At the same time a curl http://localhost to the local http server succeeds.

Could anyone please help me understand what I'm missing here? Here's my ajax code:

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Request bugs</title>
    <script src="jquery-3.1.1.min.js"></script>
</head>
<body style="background-color: black">

<div id="logs" style="width: 100%;height: 100%; background-color: black;position: absolute;color:white;padding:50px;"></div>

<script>
      $.ajax({
          url:'http://localhost',
           // This url works just fine -> url:'http://httpbin.org/', 
            type:'GET',
            async: 'true',
            dataType:'text html',
            error:function(e){
                $("#logs").html("Failure</br> " + eval(e)+$("#logs").html());
            },
            success:function(){
                $("#logs").html("Success</br>"+$("#logs").html());
             // $("#logs").html(data);
            }
        });
  </script>
</body>
</html>
  • post your debug console on that request. what error code do you get from the server? – Aus Nov 17 '16 at 11:07
  • Try changing `dataType` to `html` or remove this key. – Justinas Nov 17 '16 at 11:08
  • @GoneCoding why do you assume it is a CORS issue? he's using localhost as url and he didn't post the error code. – Aus Nov 17 '16 at 11:08
  • @GoneCoding I just read the commented out line, you're right. – Aus Nov 17 '16 at 11:10
  • 1
    @aashish try googling CORS. – Aus Nov 17 '16 at 11:11
  • If you are using chrome, just press F12, and find some red-colored info, if not , just get one – armnotstrong Nov 17 '16 at 11:13
  • Thanks everyone! I just installed a CORS plugin for Firefox and it worked just fine. Appreciate your prompt support. However, I'm still wondering how a local http server could be on a differeing domain? Never mind, I have what I need now. – Aashish Sharma Nov 17 '16 at 12:19

0 Answers0