Search code examples
tizentizen-wearable-sdktizen-web-app

Auto generated code from REST viewer not working in Tizen IDE(Wearable) web app


I'm calling one API from HTML/Javascript page using RestViewer.I'm able to get response on RestViewer for that API. However, after generating auto code it is not working in javascript.In browser it is giving error "Request cancelled".Neither of success and failure block getting called. Attached generated code for calling API.Please help if have any idea.

function callAPI() {        
    rest.get(
        'http://rest-service.guides.spring.io/greeting', 
        null, 
        null, 
        function(data, xhr) { 
            alert(data);
            // TODO success callback
        },
        function(data, xhr) { 
            alert(data);
            // TODO error callback
        }
    );
}

Debugger screenshot after API call from emulator


Solution

  • You can use this

    function getSpringServerData() {
            'use strict';
    
            console.log( "ready!" );
              $.ajax({
                type: "GET",
                url: "http://rest-service.guides.spring.io/greeting",
                success: function (data) {
                      console.log(JSON.stringify(data));
                 }
           });
        }
    

    You have to add Jquery Library to your project. Also don't forget to add privilege and allow domains in your config.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <widget xmlns:tizen="http://tizen.org/ns/widgets" xmlns="http://www.w3.org/ns/widgets" id="http://yourdomain/XXXX" version="1.0.0" viewmodes="maximized">
        <tizen:application id="qVBTv1uptg.XXXX" package="qVBTv1uptg" required_version="2.3.1"/>
        <content src="index.html"/>
        <access origin="http://spring.io" subdomains="true"></access>
        <access origin="*" subdomains="true"></access>
        <feature name="http://tizen.org/feature/screen.size.all"/>
        <icon src="icon.png"/>
        <name>XXXX</name>
        <tizen:privilege name="http://tizen.org/privilege/internet"/>
        <tizen:privilege name="http://tizen.org/privilege/application.launch"/>
        <tizen:profile name="wearable"/>
    </widget>
    

    It is working for me.

    enter image description here