I have a button in my html:
<button id="confirm-download" onclick="submit(getStudentsDetails)" data-dismiss="modal" class="btn btn-success">Confirm</button>
and these are the submit
and getStudentsDetails
functions
function submit(callback) {
$('#download_resumes').attr('action', '/api/studentsdetails/');
$('#download_resumes').submit();
callback()
}
function getStudentsDetails() {
$('#download_resumes').attr('action', '/api/studentsdetails/');
$('#download_resumes').submit();
}
Now these functions are referring to this form:
<form id = "download_resumes" action="api/" method = "POST">
The problem here is that, only the second api (/api/studentsdetails/
) is getting called here. I want both of these apis to be called onClick
of the button.
The 2 APIs that need to be called are '/api/resumes/'
, '/api/studentsdetails/'
.
Use Handler of submit and then call your second function like the following
function submit(callback) {
$('#download_resumes').attr('action', '/api/studentsdetails/');
$('#download_resumes').submit(function( event ) {
alert( "Handler for .submit() called." );
callback()
});
}
function getStudentsDetails() {
$('#download_resumes').attr('action', '/api/studentsdetails/');
$('#download_resumes').submit();
}
you can use ajax request to submit form and on success you can call that callback method
function submit(callback) {
//assuming callback is method name you want to call
$.ajax({
url:'/api/studentsdetails/',
data:$('#download_resumes').serialize(),
success:function(response){
window[callback]();
}
});
}
window[callback] (); will call your callbackmethod on success refer this link for more information.