2017-08-07 27 views
0

私は、送信ボタンをクリックした後、javascript関数を呼び出すHTML入力ボックスがあります。ユーザーが入力ボックスに入力したデータを竜巻サーバーに送信したい。私はこれすべてのことについて非常に新しく、いくつかのオプションを試しましたが、誰も動作していないようです。このコードでは、私は405(メソッドが許可されていない)エラーを取得します。ここで私が今持っているものです。JSONを使用してサーバーに文字列を送信する方法は? (トルネード)

var myData = hello 

function pushURL(){ 

    var passThis = { 
     apples : myData 
    } 

    $.ajax({ 
     url: "/", 
     type: 'POST', 
     contenttype: 'application/json; charset=utf-8', 
     data : JSON.stringify(passThis), 
     dataType: 'JSON' 
    }); 
} 

そして、ここでは私の竜巻スクリプトです:

import tornado.ioloop 
import tornado.web 
import json 

#Utility libraries 
import os.path 

class MainHandler(tornado.web.RequestHandler): 
    def get(self): 
     self.render('index.html') 

#This tells tornado where to find static files 
settings = dict(
    template_path = os.path.join(os.path.dirname(__file__), "templates"), 
    static_path = os.path.join(os.path.dirname(__file__), "static"), 
    debug = True 
) 

# r"/" == root website address 
application = tornado.web.Application([ 
    (r"/", MainHandler) 
],**settings) 

#Start the server at port n 
if __name__ == "__main__": 
    print('Server Running...') 
    print('Press ctrl + c to close') 
    application.listen(8888) 
    tornado.ioloop.IOLoop.instance().start() 

私はいくつかのサーバー側のPythonスクリプトで文字列を使用する必要があるとしてますが、今のよ私はちょうどそれがユーザーが提出をクリックするときにコンソールに印刷されて見てみたいと思います。どんな助けでも大歓迎です。また、ELI5の言葉を冷静に説明することができれば。

答えて

0

フロントエンドからインデックスへのポストリクエストとしてデータを送信しているので、MainHandlerクラスの中でポストメソッドを定義する必要があります。 この文書hereを参照してください。

関連する問題