问题
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