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>