how to use the ajax in django and how to avoid this kind of errors?

Viewed 27

I am trying to use the ajax in my django application, but its not working. I cannot find that my codes are working or not. python or django did not show any error, but javascript showing some kind of error. I will provide my code and its error here, if my code is wrong, please give me the correct code.

        html form
    <form>
    <input type = "text" name = "user" id = "user"><br>
    <span id = "mess"></span><br>
    </form><br>
    ajax in html
    {% block javascript %}
    <script>
    $(document).ready(function() {
    $('#user').keyup(function() {
    let a = $('#user').val();
    $.ajax({
                url: '{% url "username" %}',
    type: "POST",
    data: {a: a},
                        // on success
    success: function (response) {
    if (response == true) {
    $('#mess').html("username is not available");
    alert(response);
                    }
                    else {
    $('#mess').html("username is available");
    alert(response);
    }
    }
    });
    });
    });
    </script>
    {% endblock javascript %}
    urls.py path
        path('username', views.username, name = 'username'),
    views.py function
    def username(request):
        if request.is_ajax():
            user = request.POST['a']
            response = signup.objects.filter(user = user)
        #    return JsonResponse(response)
            return HttpResponse(response)
    error
    username?a=enteredword:1 Request unavailable in the network panel, try reloading the inspected page         Failed to load resource: the server responded with a status of 500 (Internal Server Error)
    Warning
    DevTools failed to load source map: Could not load content for chrome-        
    extension://gighmmpiobklfepjocnamgkkbiglidom/browser-polyfill.js.map: System error:         
    net::ERR_FILE_NOT_FOUND
1 Answers

This might work for you:

Go to Inspect → Settings (Symbol) gear → Uncheck Enable JavaScript source maps and Enable CSS source map.

Refresh.

Related