从 REST 查看器自动生成的代码在 Tizen IDE(可穿戴)Web 应用程序中不起作用 [英] Auto generated code from REST viewer not working in Tizen IDE(Wearable) web app
问题描述
我正在使用 RestViewer 从 HTML/Javascript 页面调用一个 API.我能够在 RestViewer 上获得该 API 的响应.但是,在生成自动代码后,它在 javascript 中不起作用.在浏览器中,它给出错误请求已取消".成功和失败块都没有被调用.附上调用 API 的生成代码.如果有任何想法,请帮助.
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
}
);
}
推荐答案
你可以使用这个
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));
}
});
}
您必须将 Jquery 库添加到您的项目中.另外不要忘记在 config.xml 中添加权限和允许域
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>
它对我有用.
这篇关于从 REST 查看器自动生成的代码在 Tizen IDE(可穿戴)Web 应用程序中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!