Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/406.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何抓住",;回应";使用JQuery的服务器的名称?_Javascript_Jquery_Ajax - Fatal编程技术网

Javascript 如何抓住",;回应";使用JQuery的服务器的名称?

Javascript 如何抓住",;回应";使用JQuery的服务器的名称?,javascript,jquery,ajax,Javascript,Jquery,Ajax,请看下面的代码 <!DOCTYPE html> <!-- To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor. --> <html> <head>

请看下面的代码

<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <title>TODO supply a title</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">

        <script src="//cdnjs.cloudflare.com/ajax/libs/annyang/1.1.0/annyang.min.js"></script>
        <script>
        if (annyang) {
                // Let's define our first command. First the text we expect, and then the function it should call
                var commands = {
                'hello': function() {
                    alert("Hello!");
                }
            };

        // Add our commands to annyang
        annyang.addCommands(commands);

         // Start listening. You can call this here, or attach this call to an event, button, etc.
       // annyang.start();
        }
</script>


    </head>
    <body>
        <div>TODO write content</div>
        <button onclick="annyang.start();">Start</button>
    </body>
</html>

提供头衔
如果(安阳){
//让我们定义我们的第一个命令。首先是我们期望的文本,然后是它应该调用的函数
var命令={
“hello”:函数(){
警惕(“你好!”);
}
};
//将我们的命令添加到annyang
annyang.addCommands(commands);
//开始收听。您可以在此处呼叫,或将此呼叫附加到事件、按钮等。
//annyang.start();
}
TODO写入内容
开始
JavaScript代码将数据发送到外部服务器并获得响应。导入的JS文件可在此处找到-


我的问题是,如何查看从服务器获得的“响应”?

要查看控制台中返回的结果,请通过添加以下内容打开调试模式:

annyang.debug();
或者,要捕获函数中所有可识别的文本,只需添加一个catch all函数

annyang.addCommands({
  '*transcript': function(transcript) {
    console.log(transcript);
  }
});

另外,我想您应该取消对start()命令的注释。

投票人应该进行注释。您可以使用多种工具中的一种,在浏览器中使用F12,所有现代浏览器都允许您查看响应。或者,如果您希望可以使用Fiddler()查看响应。@Qpirate:谢谢您的回复,我需要在代码中使用响应,所以我应该在代码中获取它。按F12键,然后像昆汀告诉您的那样,在那里查看回复。另外,关于Annyang,看这个:你确定有服务器参与吗?嗨,谢谢。如何获得“信心分数”?annyang的目标是封装浏览器语音识别引擎的内部工作原理及其各种问题,并为您提供易于使用的API与之交互。如果您想直接访问来自Google的原始响应,您必须直接使用浏览器的webkitSpeechRecognition实现,而不是库。