Ajax and Flask: returned undefined

  ajax, flask, javascript, jquery, python

I have this problem in my AJAX and Flask.

The error says "Uncaught TypeError: secondPassword is undefined" but secondPassword is Clearly visible in the Ajax part.

This is the AJAX Part:

$.ajax({
       data : {
             password : $('#password').val(),
             secondPassword : $('#rePass').val()
         },
       type : 'POST',
       url : '/checkSecondPassword'
       })
       .done(function(secondPassword){
           if(secondPassword.error) {
                  $('#passwordError').text(secondPassword.error);//.show();
                  $('#rePassError').text(secondPassword.error);//.show();         
            } 
        });

And this is the Flask Part:

@app.route('/checkSecondPassword', methods=['POST'])
def checkSecondPassword():
    if request.method == 'POST':
        password = request.form['password']
        repass = request.form['secondPassword']

        
        if password != repass:
            
            return jsonify({'error':"Passwords doesn't match."})

        return ('', 204)

Source: Python Questions

LEAVE A COMMENT