Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple AJAX HTTP GET using jQuery [duplicate]

I am very new to jQuery and AJAX,I am trying following code,just simple http get request.

<html>
<head>
</head>
<body>
    <script src = "jquery-2.1.4.js"></script>
    <script src = "app.js"></script>
    <script>
        $(document).ready(function(){
            $("button").click(function(){
                $.get("http://google.com", function(data, status){
                    alert("Data: " + data + "\nStatus: " + status);
                });
            });
        });
    </script>
    <button>Send an HTTP GET request to a page and get the result back</button>
</body>
</html>

and I am getting following error

XMLHttpRequest cannot load http://google.com/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'file://' is therefore not allowed access.

Please help me what am I missing.

like image 665
newhorizens Avatar asked Jan 28 '26 17:01

newhorizens


1 Answers

Same origin policy will not let you access resources hosted on a different server. In your case, if the target system is not under your control, you can look at utilities like jsonp which can help you fire cross domain requests.

like image 174
Pavan Andhukuri Avatar answered Jan 30 '26 08:01

Pavan Andhukuri



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!