Problem Checking Username in CS50 Finance : <p>For some reason, the check route does not return false when the username is unavailable. Does anyone have an idea of what I am doing wrong?</p>

<p>I have tried various different notations for the javascript code, but I have not altered the check code because it seems correct to me.</p>

<p>Here is the python code:</p>

<pre><code>@app.route("/check", methods=["GET"])
def check():
    # Return true if username available, else false, in JSON format

    username = request.form.get("username")

    taken_usernames = db.execute("SELECT username FROM users")

    if not len(str(username)) &gt; 0:
        return jsonify(False)
    for taken_username in taken_usernames:
        if username == taken_username["username"]:
            return jsonify(False)

    return jsonify(True)
</code></pre>

<p>Here is the html code using the above route:</p>

<pre><code>{% extends "layout.html" %}

{% block title %}
    Register
{% endblock %}

{% block main %}
    &lt;form action="/register" method="post" onsubmit="function(event) {
                        event.preventDefault();
                    }"&gt;
        &lt;div class="form-group"&gt;
            &lt;input autocomplete="off" autofocus class="form-control" name="username" placeholder="Username" type="text"&gt;
        &lt;/div&gt;
        &lt;div class="form-group"&gt;
            &lt;input class="form-control" name="password" placeholder="Password" type="password"&gt;
        &lt;/div&gt;
        &lt;div class="form-group"&gt;
            &lt;input class="form-control" name="confirmation" placeholder="Confirm Password" type="password"&gt;
        &lt;/div&gt;
        &lt;button class="btn btn-primary" type="submit"&gt;Register&lt;/button&gt;
    &lt;/form&gt;
{% endblock %}

{% if get_flashed_messages() %}
    &lt;script&gt;

        var username = document.querySelector('input.username');
        var register = document.querySelector('form');
        register.onsubmit = function(success) {
            $.get('/check?username=' + username, function() {
                if (success == false) {
                document.getElement('form').addEventListener("submit", function(event){
                    event.preventDefault();
                    });
                    alert('Username already taken');
                }
                else {
                    register.submit();
                }

            });
        };


    &lt;/script&gt;
{% endif %} 
</code></pre>

<p>The route is supposed to return "false" when the username is unavailable, but it returns "true".</p>
