In my node.js, express.js application I am trying to post json data to http://localhost:3000/api/delivered. The HTML file-
<html>
<body>
<input type="submit" value="submit" id="delivered"/>
</body>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js" </script>
<script type="text/javascript">
$('#delivered').on('click', function () {
var id = {"_id": "123"};
$.ajax({
type: 'POST',
url: 'http://localhost:3000/api/delivered',
contentType: 'application/json',
data : JSON.stringify(id),
dataType: "json",
success: function () {
console.log('Delivered');
},
error: function () {
alert('Error occured while entering');
}
});
});
I am getting the error-
XMLHttpRequest cannot load http://localhost:3000/api/delivered. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.