Even though I have changed it to JSONP, the CORS error is still persisting. Here is the updated code snippet:
$.ajax({
type: "POST",
url: "<a href="https://api.api.ai/v1/" rel="nofollow noreferrer">https://api.api.ai/v1/</a>" + "query?v=20150910",
contentType: "application/json; charset=utf-8",
dataType: "json",
headers: {
"Authorization": "Bearer " + accessToken
},
data: JSON.stringify({
query: input,
lang: "en",
sessionId: "mysessionid"
}),
success: function(data) {
//processResponse(data);
this.text = data.result.fulfillment.speech;
// console.log("success finally");
// console.log(this.text);
verify(data);
//return data;
// return text.result.fulfillment.speech;
},
error: function() {
//processResponse("Internal Server Error");
text = "Internal Server Error";
// console.log("Failllllllllllll");
}
});