'What is the syntax to pass a query in the ajax url using Django
I'm opening a modal with ajax, but I'm having a problem because I need to access a url on my site that needs a query
<script>
document.getElementById('myBtn2').onclick = function(){
$.ajax({
url:"{% url 'add_data' %}?filter=crew",
type:'GET',
success: function(data){
$('#modal-content2').html(data);
}
});
}
</script>
I can't access url with the query, just the url alone. for example:
url:"{% url 'index' %}"
But if I put a query in the url it still doesn't work. I think the syntax is wrong and I can't figure out what it looks like.
url:"{% url 'add_dados' %}?filter=crew" --> doesn't work
Any suggests?
Solution 1:[1]
You pass the querystring as dictionary when making an AJAX request:
document.getElementById('myBtn2').onclick = function(){
$.ajax({
url:"{% url 'add_data' %}",
type:'GET',
data: {
filter: "crew"
},
success: function(data){
$('#modal-content2').html(data);
}
});
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Willem Van Onsem |
