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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With