Reputation: 439
I am getting some data from the server via Ajax call on button click, but I would like to get the data only when the drop-down goes down, would like to avoid the call when the drop-down goes back up.
Here is my jquery
$('.button').on('click', function(){
$('.test').slideToggle('slow');
$.ajax({
type: "GET",
url: /testUrl.php,
success: function(result) {
alert(result);
});
});
Thank you
Upvotes: 0
Views: 725
Reputation: 6236
You can try this:
$('.button').on('click', function(){
var $test = $('.test');
$test.slideToggle('slow');
if (!$test.is(':visible')) {
$.ajax({
type: "GET",
url: /testUrl.php,
success: function(result) {
alert(result);
});
}
});
Upvotes: 0
Reputation: 167250
You can do this way:
$('.button').on('click', function(){
if (!$('.test').is(:visible))
$.ajax({
type: "GET",
url: /testUrl.php,
success: function(result) {
alert(result);
});
$('.test').slideToggle('slow');
});
Upvotes: 1