[Answered ]-How to capture blank return with AJAX & jQuery?

2👍

✅

The ‘error’ event in your JS will not hit, because your view doesn’t return an error.

I’m not 100% sure what you want, but you can return a 404.

views.py

def GetProduct(request, upc):
    try:
        item = Item.objects.get(upc=upc)
    except Item.DoesNotExist:
        return HttpResponseNotFound()

    return render(request, "alpha/get-product.html", {'item': item})

template

error: function() {
    $('#extra').html('Please enter valid UPC code.');
    $("input").removeAttr('disabled');
}

0👍

Thanks for the time you guys have put to this question. I have solved it. I built a logic in the template file like the following:

{% if item %}
    [ show form with some disabled fields ]
{% else %}
    [ show the same form with all fields enabled ]
{% endif %}

Thanks. 🙂

Leave a comment