我正在研究Tizen可穿戴式Web应用程序。 我正在尝试使用XHR将数据发布到服务器,
function execute()
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4) {
if (this.status == 200 || this.status == 201) {
console.log(xhttp.responseText);
jsonResponse = JSON.parse(xhttp.responseText);
rheaResponse = jsonResponse.Response;
}
} else {
console.log("Chat FAILED: " + this.status);
}
};
xhttp.open("POST", chatUrl, true);
xhttp.setRequestHeader("Content-Type", "application/json");
xhttp.send(sampleData);
}
function onBtnTap() {
recognizer.continuous = false;
recognizer.onstart = function() {
isListnining = true;
console.log("started");
};
recognizer.onend = function() {
isListnining = false
console.log("Recogniztion API stopped");
}
recognizer.start();
timer = setTimeout(stopRecognition, 8000);
recognizer.onresult = function(event) {
console.log("On result");
isListnining = false;
clearTimeout(timer);
if (event.results.length > 0) {
userInput = event.results[0][0].transcript;
updateArrays(position, userInput);
console.log(userInput);
execute(userInput);
}
}
recognizer.onerror = function(event) {
isListnining = false
console.log('Speech recognition error detected: ' + event.error);
}
}
一切都运转良好,但有时我得到的反应是两次,三次以上。假设某处请求多次命中服务器。请告诉我代码中有什么问题?为什么它会多次击中服务器。