I'm developing a node.js REST service which is being used by a web client with javascript. I was currently offering this services over HTTP. Now I have changed the server to offer them over HTTPS and ajax calls have stopped working.
When I set up the server to be over http this client code works (shows the "success!" alert):
<html>
<head>
<title>Client</title>
<script src="http://code.jquery.com/jquery-1.8.0.min.js"></script>
<script type="text/javascript">
$(function () {
$("#go").click(function (e) {
$.ajax({
type: "GET",
url: "http://localhost:3010/users",
data: { username: "test", password: "12345" },
success: function(data) {
alert("success!");
}
}).error(function (data) {
alert("error");
});
e.preventDefault();
});
});
</script>
</head>
<body>
<a id="go" href="#">go!</a>
</body>
</html>
When I change the server to use HTTPS and change the url in the client code:
$.ajax({
type: "GET",
url: "http://localhost:3010/users",
...
When I use CURL to test the server with the https calls it does work perfectly:
curl --insecure "https://localhot:3010/users?username=test&password=12345"
I don't understand why the ajax calls fail when using the https services.