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

那年仲夏 提交于 2019-12-25 14:20:10

问题


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
        }
    );
}


回答1:


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.




回答2:


have you granted the right permissions in manifest file ?

Do you have this line in yours?

<tizen:privilege name="http://tizen.org/privilege/internet"/>

Here is an example project you get inspiration from:

https://github.com/TizenTeam/mapo/blob/tizen-2.3-wearable/config.xml



来源:https://stackoverflow.com/questions/40590871/auto-generated-code-from-rest-viewer-not-working-in-tizen-idewearable-web-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!