将IBM watson API与jquery的$ .ajax一起使用 [英] Use IBM watson API with jquery's $.ajax

查看:91
本文介绍了将IBM watson API与jquery的$ .ajax一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查看watson API的文档( http://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/doc/qaapi/#apiRef )但是关于如何在客户端使用API​​没有明确的方法-side js。我想使用jquery的$ .AJAX函数。

I'm looking at the documentation for the watson API ( http://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/doc/qaapi/#apiRef ) but there isn't a clear way regarding how to use the API with client-side js. I'd like to use jquery's $.AJAX function.

如何使用jquery使用API​​对我的帐户进行身份验证并发送一个问题?一旦我获得了json格式的API,我就可以解析它,但是我该如何发送它?

How do I authenticate my account with the API using jquery and the send it a question? Once I get the json form the API, I can parse that, but how do I send it?

以下是我如何考虑这样做,但我不知道我不知道从BlueMix获取身份验证信息的位置,然后我发送请求获取JSON的位置。

Here is how I'd think about doing this, but I don't know where I get the authentication information from BlueMix and then to where I send the request to get the JSON.

var questionJSON = {
    'question': {
        'evidenceRequest': {
            'items' : 1
        },
        'questionText': question
     }
};
$.ajax({    
    url: '' // url,
    dataType: 'json',
    method: 'PUT',
    beforeSend: function(xhr){
        //xhr.setRequestHeader('Authorization', 'Basic '+btoa(accessToken+':'));
    },
    success: function(answerJSON){
        // parse answerJSON
    }
});


推荐答案

请查看我在IBM developerWorks上的教程使用Watson的问答服务 -
http://www.ibm.com/developerworks/cloud/library/cl-watson-qaapi-app/index.html#N10229

Please take a look at my tutorial on IBM developerWorks on using Watson's Question and Answer service - http://www.ibm.com/developerworks/cloud/library/cl-watson-qaapi-app/index.html#N10229

问候
Ganesh

Regards Ganesh

这篇关于将IBM watson API与jquery的$ .ajax一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆