Hi,
I'm trying to post the data from OJET to a post rest service. While doing so I'm getting error as "XMLHttpRequest cannot load http://127.0.0.1:8010/shoppingCart/create. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8383' is therefore not allowed access. The response had HTTP status code 403."
My server side rest service has @CrossOrigin(origins="*") header to handle request from all origins.
Besides this I'm trying to send request headers along with request but couldn't find a way to send headers through oj.model.save(); By exploring somewhere wrote like below code but not sure is this right way to send request headers to a post rest service.
below is my code:
JS code:
self.resourceUrl = 'http://127.0.0.1:8010/shoppingCart/create';
self.model = oj.Model.extend({
url:self.resourceUrl
});
self.add = new self.model();
// self.add.fetch({ beforeSend: setHeader });
var setHeader = function (xhr) {
console.log(setheader());
xhr.setRequestHeader('Access-Control-Allow-Origin', '*');
}
self.add.save(item,{ beforeSend: setHeader },
{success:function(model) {
console.log("success post");
}});
Can anyone please help me to resolve this issue and also provide the correct way to send request headers to a rest service.