I have a form inside a slider, and elements inside each section of the slider are controlled by their respective case in a switch statement. For example:
HTML
<ul class="slider">
<li class="slide">
<span class="next">Next</span>
</li>
<li class="slide">
<span class="next">Next</span>
</li>
<li class="slide">
<span class="next">Next</span>
</li>
</ul>
JS
$(function(){
$('.next','.slide').click(function (e) {
e.preventDefault();
var slideIndex = $(this).closest('.slide').index();
switch (slideIndex) {
case 0:
someFunction();
break;
case 1:
anotherFunction();
break;
case 2:
$.ajax({
type: "POST",
url: "http://some.site.com/register.php",
data: 'some data',
success: function (response) {
if (response)
// Call slide();
}
});
break;
default:
return false;
break;
}
slide();
});
The problem is, slide()
is always called at the end of the click function. Is there a way to only call the function after that AJAX request has given a response?
Edit
I probably didn't make myself clear enough. I know I could just call slide()
in the ajax response, but then I would also have to call it at the end of every switch case. The flow should look something like:
User clicks 'next'..
-> script checks which slide the user is on
-> do logic for that slide
-> slide()