I have created one RESTful web service which can be accessible using the below url :
http://localhost:8012/getUserData
This RESTful web service is just fetching the Name & Mobile number from database. So i want to show it on the HTML page by calling that API from HTML using Javascript.
I tried below HTML code along with javascript :
<!DOCTYPE html> <html>
<head>
<title>Hello jQuery</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="hello.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$.ajax({
type :"GET"
url: "http://localhost:8012/login"
}).then(function(data) {
$('.greeting-id').append(data.id);
$('.greeting-content').append(data.content);
});
});
</script>
</head>
<body>
<div>
<p class="greeting-id">The ID is </p>
<p class="greeting-content">The password is </p>
</div>
</body> </html>
After running this HTML code i got below error :
XMLHttpRequest cannot load http://localhost:8012/login. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
Could anyone help me to sort this problem or if I does anything wrong please correct me