This is a full flow which has to be taken care here. I am coding in Django/Python/Web Development.
I have an html page which has got a dummy button which is triggering all the functions that I want to perform now. Instead of the dummy button I want an uploadFunction() to perform the same actions. I googled and found that the best way to do this was by using AJAX, since the action to be performed requires to hit the server.
This is my uploadFunction() in jsfunctions.js file
function upload() {
//does some upload
alert('before dummy')
ajaxCallFunction();
}
I am giving a call to a ajaxCallFunction() which I have in another separate file ajax.js. The ajaxCallFunction() is as follows:
$(document).ready(function(){
function ajaxCallFunction(){
alert('right before ajax call')
$.ajax({
type: "POST",
url: "/dummy/{{ frame.slug }}/",
alert('AJAX CALL');
data: {
'snapshot' : $('#snapshot').val(),
},
success: dummy,
dataType: 'html'
alert('just finished')
}
headers:{
'X-CSRFToken':csrftoken
}
});
}
});
function dummySuccess(data, textStatus, jqXHR)
{
$('#dummySuccess').html(data)
}
I want my the upload() to call the ajaxCallFunction() and redirect it to a method in views.py (which I have mapped in my urls.py). However, my code does not hit the ajaxCallFunction at all.(I cant see the alerts that I have put in the ajaxCallFunction). In my calling page I have all of these included.
<script language="javascript" type="text/css"> </script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script language="javascript" src ="/static/js/jsfunctions.js"></script>
<script language="javascript" src ="/static/js/ajax.js"></script>
I have the the function which gets the CSRF Token
too (since this is a post method) in my ajax.js. Am I missing something here? What else do I need to do to make this ajax call? Please help. Thanks in advance :)