继续从这question继续,我设法将我的chatbot的对话历史记录保存为一个扁平的json文件。我现在想看看index.html
文件中的json的内容。我想在我的HTML使用此代码,但我得到了一个空白页面从平板JSON数据检索到HTML
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script>
$(function() {
$.getJSON('chathistory.json', function(json) {
console.log(json);
});
});
</script>
</head>
</html>
我的聊天机器人的对话记录代码:
bot.use({
botbuilder: function (session, next) {
//console.log(session.message.text);
test="\r\nUSER: "+session.message.text;
fs.appendFile(filename, test, function(err){ });
next();
},
send: function (event, next) {
//console.log(event.text);
test="\r\nBOT: "+event.text;
fs.appendFile(filename, test, function(err){ });
next();
}
});
我chathistory.json文件:
USER: hi
BOT: Hi, I am your chatbot.
BOT: What is your name?
USER: Anish
BOT: Hello, Anish. How may I help you today?
如何在我的index.html页面中看到这些数据?
确定您收到一个空白页面,但您是否检查了开发人员控制台以查看您的json是否已从文本文件正确读取?你正在得到一个空白页面,因为你的JavaScript没有对json数据做任何事情。 – victor