1
getAllOrganization: function() {
    return new Promise(function(resolve, reject) {
          request.fetch(latas.API_ENDPOINT.organizationApi).then(function(result) {
            if(result.status) {
                resolve(result.data); console.log('hi success');
            } else { console.log('rejected');
                reject(result.message);
            }
        }, function(error) { console.log('errorr');
            reject(latas.MESSAGES.SOMETHING_WENT_WRONG);
        });
    });
}

Above is my code [Promise] Which is rejecting after OPTIONS request call. I just want GET request ,I want to bypass OPTIONS request.

Bergi
  • 513,640
  • 108
  • 821
  • 1,164
Kalashir
  • 999
  • 11
  • 32
  • Are you requesting a different url than where your application is hosted? If so, the following is probably interesting: http://stackoverflow.com/questions/1256593/why-am-i-getting-an-options-request-instead-of-a-get-request and http://stackoverflow.com/questions/13814739/prototype-ajax-request-being-sent-as-options-rather-than-get-results-in-501-err/15300045#15300045 – janpieter_z Feb 19 '16 at 06:15
  • Actually I am not requesting different url or domain url in this code. – Kalashir Feb 19 '16 at 06:24
  • 3
    this has been addressed in this post http://stackoverflow.com/questions/29954037/how-to-disable-options-request – user2325727 Feb 19 '16 at 06:25
  • There is nothing in your code indicating any manual Options call. Are you sure the api endpoint isn't by accident on api.example.com while your app is on app.example.com or www.example.com? – janpieter_z Feb 19 '16 at 06:30
  • @janpieter_z Hey I have reviewed the code , Yes i am hitting different domain in this Code and Understood that why it is sending OPTIONS request but my issue is , OPTIONS request is getting rejected in the promise and it is sending null response in the code ahead , and after render() function GET is request is getting called so how to handle this ? like now which react life cycle method should i call this AJAX call. – Kalashir Feb 19 '16 at 06:51
  • Well, the OPTIONS call getting rejected is the problem for the original promise of course. It might be an idea to look which promise library you use and see if you can manipulate this. Depending on your React lifecycle, your response will come in anyway after the render is called (the ajax call is asynchronous). Do you have control over the api endpoint it's calling? You could look to implement the OPTIONS method there. – janpieter_z Feb 19 '16 at 08:08
  • Btw, avoid the [`Promise` constructor antipattern](http://stackoverflow.com/q/23803743/1048572)! – Bergi Feb 19 '16 at 14:17
  • Are you receiving [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS) headers properly? – Salva Feb 21 '16 at 12:33

0 Answers0