2016-11-07 35 views
0

Ajax & Python-Flaskを使用してフォームデータをMySQL DBに送信しようとしましたが、同じエラー "メソッドが許可されていません"メソッド要求されたURLに許可されていません エラー405:メソッドが許可されていませんフラスコ、ajax

方法

を許可されていません:と

@app.route("/signup", methods=['POST','GET']) 
def signup(): 
    try: 
     if request.method == 'POST': 
      _email =request.form["email"] 
      _firstname = request.form["firstname"] 
      _lastname = request.form["lastname"] 
      _password = request.form["password"] 
      con = mysql.connect() 
      cursor = con.cursor() 
      if _email and _firstname and _password: 
       cursor.execute("""INSERT INTO signpp (
              user_email, 
              user_fname, 
              user_lname, 
              user_password) 
            VALUES (%s,%s,%s,%s)""",(_email,_firstname,_lastname,_password)) 

       data = cursor.fetchall() 
       if len(data) is 0: 
        con.commit() 
        return jsonify(data = "User created successfully !") 
       else: 
        return jsonify(str(data[0])) 


    except Exception as e: 
     return render_template('error.html', error = str(e))   

    cursor.close() 
    con.close() 

エラーが...

<div class="modal-content"> 
     <div class="modal-header"> 
      <button type="button" class="close" data-dismiss="modal">&times;</button> 
      <h4 class="modal-title" Align="center">Create Account</h4> 
     </div> 
     <form role="form" method="POST"> 
     <div class="modal-body"> 
      <p id="msg"></p> 
      <input class="form-control" name="email" type="text" Placeholder="Email"></input><br /> 
      <input class="form-control" name="firstname" type="text" Placeholder="First Name"></input><br /> 
      <input class="form-control" name="lastname" type="text" Placeholder="Last Name"></input><br /> 
      <input class="form-control" name="password" type="password" Placeholder="Password"></input><br /> 
      <input class="form-control" type="password" Placeholder="Confirm Password"></input> 
     </div> 
     <div class="modal-footer"> 
      <button id="btncheck" class="btn btn-danger" type="submit" >Signup</button> 
     </div> 
     </form> 
     </div> 

    </div> 
    </div> 
</div> 

<script>  

$(function(){ 

    $("#btncheck").submit(function(){ 
    $.ajax({ 
    url: '/signup', 
    type: 'POST' 
    success: function(res){ 
      console.log(res); 

     } 

    }); 
    }); 

Pythonのコードを私を助けて。

+0

私の答えが助けた場合は、アップ票を考えるか、答えとして私の答えをマークしてください。 –

答えて

0

私はそれがタイプミスかどうか確信していますが、type: 'POST'の後にカンマを忘れてしまいました。

秘密情報などの機密データを平文で送信しています。私は最初にそれを暗号化することをお勧めします。最も一般的な手法の1つはbcrypt

+0

あなたの提案に感謝し、それを暗号化しますが、問題は解決していません.... –

+1

あなたの投稿にあなたのデータを保存する変数はありますか?私はあなたのコードで@LokeshTiwariを呼び出すことはありません –

+0

@MisterPositiveデータ変数を更新した後、うまくいっていることthanx多く –

1

です。あなたのWebサービスがあなたのajax呼び出しに応答するデータはどれも期待していますか?もしそうなら、私はあなたがどこにそれを渡しているのか見当たらず、このエラー(非適合の署名)を投げることができます。データ:例として

yourDataHere

var params = { StateId: stateid }; 

$.ajax({ 
    dataType: 'json', 
    type: 'post', 
    url: 'YOURURLHERE', 
    data: params, 
    error: function (request, status, error) { 
     alert('Error: ' + error); 
    }, 
    success: function (result) { 
     $('#body').html(result); 

         } 
}); 
+0

まだ動作していません... –

+0

ajax呼び出しでsectionedエラーが定義されていますか?あなたがデバッグするときに成功セクションをヒットしますか? –

+0

リソースを読み込めませんでした:サーバーは405の状態で応答しました(方法は許可されていません)コンソールでエラーが発生しました... –

関連する問題