Home > other >  How to filter the database through dropdown with the help of ajax?
How to filter the database through dropdown with the help of ajax?

Time:06-17

Thank you for your help. I have a template that takes a value from the user via dropdown, then this value is sent to the server via ajax. I want to filter the database data based on this value. But after filtering, the queryset value in the template is empty. Why is the queryset empty? my template: my ajax code views code: Filter data based on data received from the user via ajax Where filtered data should be displayed: enter image description here What is currently displayed: There is no data

CodePudding user response:

In your template, in the ajax code, instead of:

$('#select').on('change', function (){

try:

$('#select').change(function (e) {

Also, whichever browser you're using, using the 'web developer tools' navigate to the 'network' tab and you will see which requests are being sent and received as each event is fired. This will help with identifying the problem.

CodePudding user response:

I answered this in a similar question. You have to actually do something in your success function. You have to tell it what you want to happen with the returned data

django render not updating context

  • Related