How To Apply Ajax To Get Data In Dropdown?
i am using django as a backend to query my result.Like i have three dropdown and in my views I am using the value from first two drop down to bind the data in third dropdown. I kno
Solution 1:
Are you trying to retrieve some data to use in the third select? You can do this:
$.ajax({
url: 'The url to the view',
type: 'GET', //Use POST if database modification would occurdata: {
'first_select': $('#first-select').val(),
'second_select': $('#second-select').val()
},
success: function(data){
//data contains whatever your view returns. If it's html, then add it to the select directly like $('#select').html(data); but if it's json response, Use it as you wish
},
error: function(xhr){
alert(xhr.status + ": " + xhr.responseText);
}
})
I'd recommend that you add this just before closing the body tag on your page and not within the page.
You may define some {% block script %}{% endblock %}
in the base template that you've inherited and override that block to add your scripts in there.
Post a Comment for "How To Apply Ajax To Get Data In Dropdown?"