Problems with Javascript and CORS

Skip to first unread message

Joanne Halliwell

Mar 27, 2017, 12:01:20 PM3/27/17
to Taffy Users

I've got an existing REST API running on Taffy which has been working fine, however I've now got a client who wants to integrate using Javascript. I've enabled the allowCrossDomain setting in the framework but I'm still getting preflight error messages in my test harness.

It's a very simple piece of code that is calling the API

function test(){

    alert("in function");

    var jsonBody = {};
    jsonBody.matterReference = 'testRef1';

    var xhr = new XMLHttpRequest();  
    xhr.setRequestHeader("Authorization","Basic " + btoa("gazealdemo" + ":" + "letmein001"));

     alert("end function");

However the output in Chrome is throwing the following:

OPTIONS 403 (Forbidden)
XMLHttpRequest cannot load Response for preflight has invalid HTTP status code 403

I can get it working by putting the following in the onTaffyRequest()

if (findNoCase(verb,"options")){
            return newRepresentation()

but it doesn't return the correct data, which should be a reference from our system.

Can anyone help with this?
Reply all
Reply to author
0 new messages