Method not allowed - Flask

I’m using ajax for sending the input obtained by speech recognition to the flask. The backend is fine but the ajax is, in my idea, causing synchronization problems. Whenever I send data it replies with NoneType object is not subscriptable.

This is the code

<form class="msger-inputarea" method="POST" action="mainpage">
    <input type="text" class="msger-input" name="msg">
    <button type="button" onclick="record()" class="msger-send-btn">Speak</button>
    <button type="submit" class="msger-send-btn" onclick="bubble()">Send</button>
        url: "mainpage",
        data: {'message' : message},
        dataType: "JSON",
        type: "POST",
        success: function(data) {
          var side = $("<div />").addClass("msg left-msg").appendTo("#speaker");
          var bubble = $("<div />").addClass("msg-bubble").appendTo(side);
          var info = $('<div />').addClass("msg-info").text("Bot").appendTo(bubble)
              text = $("<div />").addClass("msg-text").text(data.reply).appendTo(bubble);

It would be great if anyone could show light on this.