"Failed to load....No Access Control Allow Origin."

  • 16 February 2021
  • 0 replies
  • 57 views

Userlevel 5
Badge +20
 

"Failed to load....No Access Control Allow Origin."

KBS100128

PRODUCT
K2 Five 5.0
BASED ON
K2 Five 5.0
TAGS
Integration
REST
API
How to Document
This article was created in response to a support issue logged with K2. The content may include typographical errors and may be revised at any time without notice. This article is not considered official documentation for K2 software and is provided "as is" with no warranties.

Issue

When using the Workflow Rest API in your Javascript file, the following issue may occur when loading that page:

 

Image

 

"Failed to load https://[site]/Api/Workflow/preview/workflows/?_=1523444398270: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://[site]' is therefore not allowed access. The response had HTTP status code 400."

Symptoms

This may occur when you follow this documentation:

https://help.k2.com/onlinehelp/k2five/devref/5.0/default.htm#Runtime/WF-REST-API/WF-REST-js.htm

 

Image

Resolution

Our developers identified this as an issue within the product.

 

Workaround for K2 5.0 customers

Remove the authorization header from the AJAX call, this will let the browser prompt you for the username/password.

 

See the below example which works for K2 5.0 and returns the result back into the body of the html.

 

<html>
<head>
<script type="text/javascript" src="jquery-3.3.1.js"></script>
<script type="text/javascript">

$.ajaxSetup ({
cache: false // Disable caching of AJAX responses
});

$(document).ready(function() {
$.ajax({
type: 'GET',
url: 'https://k2.denallix.com/Api/Workflow/preview/workflows/',
dataType: 'json',
crossDomain: true,
xhrFields: {
withCredentials: true
},
success: function(json_data) {
console.log('success');
$("#wfs").html(JSON.stringify(json_data));
},
error: function() {
alert('Failed!');
},
});
});
</script>
</head>
<body>
<span id='wfs'>(Result)</span>
</div>
</body>
</html>

 

However, we recommend upgrading the environment to K2 5.1 because the issue has been resolved in that version.


0 replies

Be the first to reply!

Reply