我无法使用Concept N连接到互联网。我使用jquery和一个简单的$ .get,但它只是不起作用。有人可以帮我这个吗?
答案 0 :(得分:0)
您实际上需要使用da.getXHr()函数来访问外部Web服务。以下是如何使用jquery访问rss数据的示例。首先要做的是下载jquery并将其包含在index.html文件中:
<script type="text/javascript" src="app/jquery.min.js"></script>
现在使用此代码段来访问带有jquery的rss网址。一定要更换线路&#34; ** Enter-rss-2.0-url-here **&#34;用你自己的rss url
/*
* Copyright 2016 Sony Corporation
*/
var title;
var description;
/**
* The callback to prepare a segment for play.
* @param {string} trigger The trigger type of a segment.
* @param {object} args The input arguments.
*/
da.segment.onpreprocess = function (trigger, args) {
console.log('onpreprocess', { trigger: trigger, args: args });
//da.startSegment(null, null);
$.ajax({
url:"** Enter-rss-2.0-url-here **",
type: "GET",
dataType: 'xml',
xhr: function () { return da.getXhr(); },
error: function (jqXHR, textStatus, errorThrown) {
console.log('ajax error jqXHR.status[' + jqXHR.status + ']');
def.reject("failed with error "+jqXHR.status);
return;
},
success: function (data, textStatus, jqXHR) {
$(data).find("item:first").each(function() {
title = $(this).find("title").text();
description = $(this).find("description").text()
})
da.startSegment(null, null)
}
})
};
/**
* The callback to start a segment.
* @param {string} trigger The trigger type of a segment.
* @param {object} args The input arguments.
*/
da.segment.onstart = function (trigger, args) {
console.log('onstart', { trigger: trigger, args: args });
var synthesis = da.SpeechSynthesis.getInstance();
synthesis.speak("Title "+title+", Content "+description, {
onstart: function () {
console.log('speak start');
},
onend: function () {
console.log('speak onend');
da.stopSegment();
},
onerror: function (error) {
console.log('speak cancel: ' + error.messsage);
da.stopSegment();
}
});
};