Reputation: 993
I have a button that needs to call a method in my views.py. It just needs to call a funtion, it doesn't need to send any information to the view, just call it.
This is the button:
<a class="welcome-page-right hidden-xs hidden" href="#page-slider" data-slide="next" id="right"><i class="fa fa-chevron-right"></i></a>
I have used ajax to call a view already, im using ajax because i don't want the page to reload:
$("#Plane").onclick(function(event){
event.preventDefault();
var data = new FormData($('form').get(0));
$.ajax({
type:"POST",
url:"{% url 'calculate' %}",
data: data,
processData: false,
contentType: false,
csrfmiddlewaretoken: '{{ csrf_token }}',
success:
....
});
});
Here i was sending info from a Form to the view. Now i need just to call a view, again without reloading the page.
I guess it must be something similar to the code above but because i know little to nothing about ajax and javascript it is quite difficult
Thanks in advance
Upvotes: 2
Views: 683
Reputation: 855
Well calling a view is simply accomplished by accessing an URL, if you don't need any parameters just do not send anything.
$.ajax({
type:"POST",
url:"{% url 'calculate' %}",
data: {},
processData: false,
contentType: false,
/*csrfmiddlewaretoken: '{{ csrf_token }}',*/
success: function() {...}
});
You shouldn't need the csrf_token either.
Upvotes: 2