I am making a app for Samsung TV with Tizen studio. I am fetching data from API, the endpoint is simple a GET endpoint. The same code works in other browsers or if I open the Html file in the browser the API succeeded and got response. But in the Samsung TV, it is getting empty response. Here is the code that I am using,
const apiUrl = 'https://example.com/apiGetEndpoint';
// Create a new XMLHttpRequest object
var xhr = new XMLHttpRequest();
// Configure the GET request
xhr.open('GET', apiUrl, true);
// Set up a callback function to handle the response
xhr.onreadystatechange = function () {
// Check if the request is complete
if (xhr.readyState === 4) {
// Check if the response status is OK (status code 200)
if (xhr.status === 200) {
// Parse the response as JSON
// var response = JSON.parse(xhr.responseText);
console.log("XHR: ", xhr);
var response = xhr.responseText;
// Handle the response data
console.log("Response: ", response);
} else {
// Handle the error (e.g., display an error message)
console.error('Request failed with status:', xhr.status);
}
}
};
// Send the GET request
xhr.send();
I am really stucked on that, if you know the solution please let me know. Thanks in advance!
Check this link. I suppose that you are missing content-security-policy entry in your application config.xml file.
Just add your url(https://example.com/apiGetEndpoint) to config to allow it to be a connect-src.
<tizen:content-security-policy>default-src 'self'; connect-src 'self' https://example.com/apiGetEndpoint; style-src 'self' 'unsafe-inline';</tizen:content-security-policy>
If above will not solve your problem, you can also check this page for more possible problem causes.