-2

I know I need to change it to JSONP but the CORS error still there. here is the code. baseUrl is var baseUrl = "https://api.api.ai/v1/";

    $.ajax({
        type: "POST",
        url: baseUrl + "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");
        }
    });
Ashraful Islam
  • 546
  • 2
  • 8

1 Answers1

0

I'm not sure. But in my case, it's easily solved by adding { 'Access-Control-Allow-Origin': '*' } at response header in server side.

migos
  • 86
  • 1
  • 6