Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' he

User_10PCJOct 5 2016 — edited Oct 6 2016

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.

Comments
Post Details
Added on Oct 5 2016
3 comments
5,506 views