-1

I've made this simple html page but get "error" alert popup when calling example.com. Why?

<!DOCTYPE html>
<html>
    <body>
        <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.min.js"></script>
        <script type="text/javascript">
            function errorAlert(e, jqxhr) {
                alert("Your request was not successful: " + jqxhr);
            }
            function processData() {
                alert("success")
            }
            $.ajax(
            {
                type: "post",
                url: "http://example.com",
                success: processData,
                error: errorAlert
            }); //end of $.ajax
            </script>
    </body>
</html>

I'm running on Chrome 45.0...

1 Answers1

0

You can see different types of JavaScript errors in the developer console (F12 in Google Chrome). You will see: "XMLHttpRequest cannot load http://example.com/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access."

Take a look here for a detailed explanation: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '...' is therefore not allowed access

But basically, the host you send the request to must match the origin, or explicitly allow foreign hosts.

Community
  • 1
  • 1
alepeino
  • 9,551
  • 3
  • 28
  • 48