Use IBM watson API with jquery $ .ajax
I look at the documentation for the watson API ( http://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/doc/qaapi/#apiRef ) but there is no clear way to use the API with client-side js. I would like to use jquery's $ .AJAX function.
How do I authenticate my account to the API using jquery and send a question to it? Once I get the json API form, I can parse that, but how do I submit it?
This is how I might think about it, but I don't know where I am getting the authentication data from from BlueMix, and then where I am sending the request to receive 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
}
});
source to share
Please check out my IBM developerWorks tutorial on using the Watson Q&A service - http://www.ibm.com/developerworks/cloud/library/cl-watson-qaapi-app/index.html#N10229
Ganesh relationship
source to share
I believe you may need to use similar logic as shown below:
function addUser(event)
{
.......................
$.ajax({
url: '/users/adduser',,
dataType: 'json',
method: 'PUT',
beforeSend: function(xhr){
//xhr.setRequestHeader('Authorization', 'Basic '+btoa(accessToken+':'));
},
success: function(answerJSON){
// parse answerJSON
}
});
};
/ * * POST to adduser. * /
router.post('/adduser', function(req, res) {
var db = req.db;
db.collection('userlist').insert(req.body, function(err, result){
res.send(
(err === null) ? { msg: '' } : { msg: err }
);
});
});
you can follow the link below for more client side js information:
http://cwbuecheler.com/web/tutorials/2014/restful-web-app-node-express-mongodb/
source to share
You are trying to do cross domain queries ( http://en.wikipedia.org/wiki/Same-origin_policy ). It's impossible.
The only way to call qa service from client side is with jsonp ( http://en.wikipedia.org/wiki/JSONP ). but this is not currently supported. I suggest you create an application in Bluemix and use it as a proxy between your code and the service.
source to share