ajax response to be filtered using user input

Question!

I am writting a Djagno application which consists of: template(html) js(jquery) views.py(python backend)

UI has 2 drop down: On selecting 1st drop down, i get result from views.py which contains 2nd drop down value and other result.

Now I am able to make ajax call and get result and update 2nd drop down on selecting 1st drop down. But question is I am not sure how I can accept value from 2nd drop down, and use that to filter on ajax response and render the output.

2nd drop down value and return response[2nd_drop_down] to html as table.

Thanks in advance.

Currently my Jquery code has:

$(function(){
    $("#1st_dropdown_id").change(function(){
        //make_ajax_call()
    })

    $("#2nd_dropdown_id").change(function(){
        // how to access ajax response here
    })
})

function make_ajax_call(){
    $.ajax({
        type : "GET", 
        url : "python_backend_file", 
        contentType: 'application/json',
        data : { 
            fleet: $('#fleet').val(),
            csrfmiddlewaretoken:$('input[name=csrfmiddlewaretoken]').val()
        },  
        success : function(response) {
            //poplate 2nd drop down
        },  
        error : function(xhr,errmsg,err) {
            alert("fail")
        }
    });
}


Answers

How about:

var ajaxResponse; // declare variable

$(function(){
    ...

    $("#2nd_dropdown_id").change(function(){
        // how to access ajax response here
        ... access ajaxResponse variable here
    })
})

function make_ajax_call(){
    $.ajax({
        ...
        success : function(response) {
            ...
            ajaxResponse = response; // assign value to ajaxResponse variable
        }
        ...
    });
}


There are two approaches:

1st one:

List<Orders> findBySaleTimeBetween(DateTime start, DateTime end);

2nd one:

List<Orders> findBySaleTime(DateTime date);

It's worth trying to save dates rounded as much as possible, so if you only need day, set hours and minutes to certain values for all the entities.

By : xenteros


You can use a WHERE clause for this. Convert your INSERT VALUES to an INSERT SELECT and add a WHERE clause.

For example,

INSERT INTO fields (field_name, control_type_id, needs_approval)
SELECT
'Array Photos', 3, 0
WHERE Condition;

If Condition is true, it will insert the row. If Condition is false, the SELECT will return zero rows and thus the INSERT will insert zero rows.



This video can help you solving your question :)
By: admin