0

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

nik
  • 1,464
  • 4
  • 18
  • 32

2 Answers2

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.

enter image description here

Iqbal hossain
  • 1,778
  • 3
  • 17
  • 24
-1

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

RzR
  • 3,068
  • 29
  • 26
  • @ RzR -Thanks for your response.I'm new in Tizen.So could u please tell me more about manifest file or refer some tutorial regarding to manifest file? – nik Nov 15 '16 at 05:21