Search code examples
xmlhttprequesttoasttizensamsung-smart-tv

XmlHttpRequest on Tizen TV exits application


I am currently developping an app for Samsung Tizen and WebOS TVs. For this, I am using Samsung's TOAST and Caph with angular1.

The generated .wgt is working fine on browser and TV Simulator, but on real device, the application exits when an XMLHttpRequest is sent.

Here is the code:

    var url = "grant_type=password&username=" + $scope.logInfos.loginEmail + "&password=" + $scope.logInfos.loginPassword;
    var xhr = new XMLHttpRequest();
    xhr.open('POST', 'https://myUrl/token');
    xhr.onreadystatechange = function() {
        xhr.onloadend = function() {
            if (xhr.response) {
                console.log("logged in");
            }
        };
    };
    xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xhr.send(url);

These lines are launched when the login form is submitted but at this moment the application exits. There are no error message in the console and no trace of the xhr in the network tab.

I tried changing HTTPS to HTTP in case this was the problem but it did nothing.

Could you please help?


Solution

  • Don't forget to add privilege and allow domains in your config.xml

    <access origin="*" subdomains="true"></access>
    <tizen:privilege name="http://tizen.org/privilege/internet"/>