我正在尝试在我的一个文件夹中的sqlite数据库中插入文本。我似乎没有任何进展。我正在使用this的指南。 AM使用XMLHTTPRequest,并使用sql.js打开我的数据库 这是我的代码:
// set up the stage
container.classList.add("bubble-container")
var bubbleWrap = document.createElement("div")
bubbleWrap.className = "bubble-wrap"
container.appendChild(bubbleWrap)
// install user input textfield
this.typeInput = function(callbackFn) {
var inputWrap = document.createElement("div")
inputWrap.className = "input-wrap"
var inputText = document.createElement("textarea")
inputText.setAttribute("placeholder", "Ask me anything...")
var xhr = new XMLHttpRequest();
xhr.open('GET', '/path/to/test/databases/storage.sqlite', true);
xhr.responseType = 'text';
inputWrap.appendChild(inputText)
inputText.addEventListener("keypress", function(e) {
// register user input
xhr.onload = function(e) {
var uInt8Array = new Uint8Array(this.response);
var db = new SQL.Database(uInt8Array);
var contents = db.exec("INSERT INTO message (name) VALUES ('inputText');");
};
xhr.send();
if (e.keyCode == 13) {
e.preventDefault()
typeof bubbleQueue !== false ? clearTimeout(bubbleQueue) : false // allow user to interrupt the bot
var lastBubble = document.querySelectorAll(".bubble.say")
lastBubble = lastBubble[lastBubble.length - 1]
lastBubble.classList.contains("reply") &&
!lastBubble.classList.contains("reply-freeform")
? lastBubble.classList.add("bubble-hidden")
: false
addBubble(
'<span class="bubble-button bubble-pick">' + this.value + "</span>",
function() {},
"reply reply-freeform"
)
// callback
typeof callbackFn === "function"
? callbackFn({
input: this.value,
convo: _convo,
standingAnswer: standingAnswer
})
: false
this.value = ""
}