Reputation: 373
Maybe this seems a really noob question, but I can't figure out what I do wrong. What I want to accomplish is a simple AJAX request. Here is my code on server side:
http.createServer(function(request, response) {
response.writeHead(200, {
"Content-Type": "text/html"
});
response.end("No data to return.");
}).listen(8666);
On client side I use jQuery:
$(document).ready(function() {
$("#magicSend").on("click", function() {
$.ajax({
url: "http://localhost:8666/",
type: "POST"
});
});
});
The problem is, that according to Firebug I'm getting the response headers but not the content. The AJAX call also gets red on Firebug's console, although it shows "200 OK". I know I miss something but can't figure out what.
Upvotes: 2
Views: 691
Reputation: 3269
Is not working because of the same origin policy.
It maybe not obvious but browsers also enforce the policy down-to the port number.
So http://example.com:80 is different from http://example.com:81
You can get around it with jsonp.
Upvotes: 0
Reputation: 9382
Are you running your webserver on port 8666 also? Judging by your code, all your NodeJS server does is serve a single answer, so I'm guessing not. You cannot make AJAX calls to a different port, even if it's the same host (localhost in your case).
Upvotes: 2