0

在我的示例中,如果用户单击“是”按钮将返回对话文本。但我希望它从我的输出中返回一个值,即我的AJAX Post示例的返回值,该值目前仅来自“ alert (output.request.number)”。怎么做?遵循以下代码:

在对话中意图:#goodbye和两个实体:@goodbye:yes@goodbye:no。如果我的客户端识别出意图并且用户单击“是”按钮,将返回一些东西

我的 JSON 高级(对话服务)

    {
      "output": {
        "text": "You can finish the conversation? \n \n 
<button id=\"button-yes\" onclick=\"OneFunction();\">Yes</button> 
<button id=\"button-no\" onclick=\"OtherFunction();\">No</button>"
      }
    }

alert(output.request.number)如果用户单击按钮,我需要返回来进入 Watson 的对话流。

JS代码:

function OneFunction(firstParameter, secondParameter){
 console.log(firstParameter);
    $.ajax({
        type: 'POST',
        dataType: 'json',
        contentType: "application/json",
        url: 'http://xxxxxxxxxxxxxxxxxxxxxxxx/request/create',
        data: JSON.stringify({
            "dataOne":firstParameter,
            "synchronize":false,              
            }
        }), 
    success:function(output, input, response) {
      console.log(output);
     // alert(output.request.number);
      var responseText = null;
      var outputTest = {};
      outputTest = output.request.number;
      var latestResponse = Api.getResponsePayload();
      // console.log(latestResponse);
      var context = latestResponse.context;
      Api.sendRequest = ("Yes", + outputTest);  // THIS RETURN one number of request
}
4

1 回答 1

0

我尝试并工作,错误只是,介于两者之间("Yes" + outputTest); 但是您的信息对此至关重要,谢谢@Michal Bida 和@timd。:

success:function(output, input, response) {
      console.log(output);
     // alert(output.request.number);
      var responseText = null;
      var outputTest = {};
      outputTest = output.request.number;
      var latestResponse = Api.getResponsePayload();
      // console.log(latestResponse);
      var context = latestResponse.context;
      Api.sendRequest = ("Yes" + outputTest);  // THIS RETURN one number of request
于 2016-12-08T12:38:46.860 回答