I have a webservice in my node.js web app (placed on amazon ec2) and it takes email address and saves it to mongodb. This webservice is placed on
var output = '<p style="color: white">Thanks, we will be in touch!</p>';
XMLHttpRequest cannot load http://example.com/mail.
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://www.example.com' is therefore not allowed access.
The access control rules consider the URL method ("http" or "https"), the whole domain name, and the port number. The rules don't "think" about the URL; it's a straight textual comparison.
Thus, "www.example.com" and "example.com" are considered two distinct domains, and so cross-origin rules apply.
You can use the URL
"/mail" in your
$.ajax() call instead, which will use the same method and domain and port as the containing page.
(Edited - I was confused or undercaffeinated or both. Should be "/mail" with one slash.)