JavaScript callback functions not executed












0















I just started learning about callback functions. Unfortunately I can't make this altered sample-code work.



<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript">

$(document).ready( function() {
$(".closebtn").click(function(){
function1(someVariable, function() {
function2(someOtherVariable);
});
});


function function1(param, callback) {
alert("Erste Funktion");
callback();
}

function function2(param) {
alert("Zweite Funktion");
}
})

</script>


When I click on the button nothing happens. Can anyone help?










share|improve this question























  • Add a button with the class closebtn and initialising the variable, this code works. What error are you getting?

    – George
    Nov 21 '18 at 15:29






  • 1





    You don't show the button so we can only guess that the button does not have the class name closebtn. Maybe you meant the id #closebtn? You should also get some errors since someVariable and someOtherVariable are undefined in the code shown.

    – Shilly
    Nov 21 '18 at 15:29








  • 1





    We'd need to see a more complete example. Fundamentally, you're passing the callback into function1 correctly and calling it correctly. Please update your question with a Minimal, Complete, and Verifiable example demonstrating the problem, ideally a runnable one using Stack Snippets (the [<>] toolbar button; here's how to do one).

    – T.J. Crowder
    Nov 21 '18 at 15:29


















0















I just started learning about callback functions. Unfortunately I can't make this altered sample-code work.



<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript">

$(document).ready( function() {
$(".closebtn").click(function(){
function1(someVariable, function() {
function2(someOtherVariable);
});
});


function function1(param, callback) {
alert("Erste Funktion");
callback();
}

function function2(param) {
alert("Zweite Funktion");
}
})

</script>


When I click on the button nothing happens. Can anyone help?










share|improve this question























  • Add a button with the class closebtn and initialising the variable, this code works. What error are you getting?

    – George
    Nov 21 '18 at 15:29






  • 1





    You don't show the button so we can only guess that the button does not have the class name closebtn. Maybe you meant the id #closebtn? You should also get some errors since someVariable and someOtherVariable are undefined in the code shown.

    – Shilly
    Nov 21 '18 at 15:29








  • 1





    We'd need to see a more complete example. Fundamentally, you're passing the callback into function1 correctly and calling it correctly. Please update your question with a Minimal, Complete, and Verifiable example demonstrating the problem, ideally a runnable one using Stack Snippets (the [<>] toolbar button; here's how to do one).

    – T.J. Crowder
    Nov 21 '18 at 15:29
















0












0








0








I just started learning about callback functions. Unfortunately I can't make this altered sample-code work.



<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript">

$(document).ready( function() {
$(".closebtn").click(function(){
function1(someVariable, function() {
function2(someOtherVariable);
});
});


function function1(param, callback) {
alert("Erste Funktion");
callback();
}

function function2(param) {
alert("Zweite Funktion");
}
})

</script>


When I click on the button nothing happens. Can anyone help?










share|improve this question














I just started learning about callback functions. Unfortunately I can't make this altered sample-code work.



<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript">

$(document).ready( function() {
$(".closebtn").click(function(){
function1(someVariable, function() {
function2(someOtherVariable);
});
});


function function1(param, callback) {
alert("Erste Funktion");
callback();
}

function function2(param) {
alert("Zweite Funktion");
}
})

</script>


When I click on the button nothing happens. Can anyone help?







javascript callback






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 '18 at 15:26









user838531user838531

13419




13419













  • Add a button with the class closebtn and initialising the variable, this code works. What error are you getting?

    – George
    Nov 21 '18 at 15:29






  • 1





    You don't show the button so we can only guess that the button does not have the class name closebtn. Maybe you meant the id #closebtn? You should also get some errors since someVariable and someOtherVariable are undefined in the code shown.

    – Shilly
    Nov 21 '18 at 15:29








  • 1





    We'd need to see a more complete example. Fundamentally, you're passing the callback into function1 correctly and calling it correctly. Please update your question with a Minimal, Complete, and Verifiable example demonstrating the problem, ideally a runnable one using Stack Snippets (the [<>] toolbar button; here's how to do one).

    – T.J. Crowder
    Nov 21 '18 at 15:29





















  • Add a button with the class closebtn and initialising the variable, this code works. What error are you getting?

    – George
    Nov 21 '18 at 15:29






  • 1





    You don't show the button so we can only guess that the button does not have the class name closebtn. Maybe you meant the id #closebtn? You should also get some errors since someVariable and someOtherVariable are undefined in the code shown.

    – Shilly
    Nov 21 '18 at 15:29








  • 1





    We'd need to see a more complete example. Fundamentally, you're passing the callback into function1 correctly and calling it correctly. Please update your question with a Minimal, Complete, and Verifiable example demonstrating the problem, ideally a runnable one using Stack Snippets (the [<>] toolbar button; here's how to do one).

    – T.J. Crowder
    Nov 21 '18 at 15:29



















Add a button with the class closebtn and initialising the variable, this code works. What error are you getting?

– George
Nov 21 '18 at 15:29





Add a button with the class closebtn and initialising the variable, this code works. What error are you getting?

– George
Nov 21 '18 at 15:29




1




1





You don't show the button so we can only guess that the button does not have the class name closebtn. Maybe you meant the id #closebtn? You should also get some errors since someVariable and someOtherVariable are undefined in the code shown.

– Shilly
Nov 21 '18 at 15:29







You don't show the button so we can only guess that the button does not have the class name closebtn. Maybe you meant the id #closebtn? You should also get some errors since someVariable and someOtherVariable are undefined in the code shown.

– Shilly
Nov 21 '18 at 15:29






1




1





We'd need to see a more complete example. Fundamentally, you're passing the callback into function1 correctly and calling it correctly. Please update your question with a Minimal, Complete, and Verifiable example demonstrating the problem, ideally a runnable one using Stack Snippets (the [<>] toolbar button; here's how to do one).

– T.J. Crowder
Nov 21 '18 at 15:29







We'd need to see a more complete example. Fundamentally, you're passing the callback into function1 correctly and calling it correctly. Please update your question with a Minimal, Complete, and Verifiable example demonstrating the problem, ideally a runnable one using Stack Snippets (the [<>] toolbar button; here's how to do one).

– T.J. Crowder
Nov 21 '18 at 15:29














1 Answer
1






active

oldest

votes


















1














Your example works for me. Let me know what you think:






// these need to be defined
var someVariable = 'example value';
var someOtherVariable = 'example value';

$(document).ready(function() {
$(".closebtn").click(function() {
function1(someVariable, function() {
function2(someOtherVariable);
});
});


function function1(param, callback) {
console.log("Erste Funktion");
callback();
}

function function2(param) {
console.log("Zweite Funktion");
}
})

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button class="closebtn">Close</button>








share|improve this answer
























  • yes, it works, it was necessary to declare the variables. thank you!

    – user838531
    Nov 22 '18 at 10:05











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53415319%2fjavascript-callback-functions-not-executed%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Your example works for me. Let me know what you think:






// these need to be defined
var someVariable = 'example value';
var someOtherVariable = 'example value';

$(document).ready(function() {
$(".closebtn").click(function() {
function1(someVariable, function() {
function2(someOtherVariable);
});
});


function function1(param, callback) {
console.log("Erste Funktion");
callback();
}

function function2(param) {
console.log("Zweite Funktion");
}
})

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button class="closebtn">Close</button>








share|improve this answer
























  • yes, it works, it was necessary to declare the variables. thank you!

    – user838531
    Nov 22 '18 at 10:05
















1














Your example works for me. Let me know what you think:






// these need to be defined
var someVariable = 'example value';
var someOtherVariable = 'example value';

$(document).ready(function() {
$(".closebtn").click(function() {
function1(someVariable, function() {
function2(someOtherVariable);
});
});


function function1(param, callback) {
console.log("Erste Funktion");
callback();
}

function function2(param) {
console.log("Zweite Funktion");
}
})

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button class="closebtn">Close</button>








share|improve this answer
























  • yes, it works, it was necessary to declare the variables. thank you!

    – user838531
    Nov 22 '18 at 10:05














1












1








1







Your example works for me. Let me know what you think:






// these need to be defined
var someVariable = 'example value';
var someOtherVariable = 'example value';

$(document).ready(function() {
$(".closebtn").click(function() {
function1(someVariable, function() {
function2(someOtherVariable);
});
});


function function1(param, callback) {
console.log("Erste Funktion");
callback();
}

function function2(param) {
console.log("Zweite Funktion");
}
})

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button class="closebtn">Close</button>








share|improve this answer













Your example works for me. Let me know what you think:






// these need to be defined
var someVariable = 'example value';
var someOtherVariable = 'example value';

$(document).ready(function() {
$(".closebtn").click(function() {
function1(someVariable, function() {
function2(someOtherVariable);
});
});


function function1(param, callback) {
console.log("Erste Funktion");
callback();
}

function function2(param) {
console.log("Zweite Funktion");
}
})

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button class="closebtn">Close</button>








// these need to be defined
var someVariable = 'example value';
var someOtherVariable = 'example value';

$(document).ready(function() {
$(".closebtn").click(function() {
function1(someVariable, function() {
function2(someOtherVariable);
});
});


function function1(param, callback) {
console.log("Erste Funktion");
callback();
}

function function2(param) {
console.log("Zweite Funktion");
}
})

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button class="closebtn">Close</button>





// these need to be defined
var someVariable = 'example value';
var someOtherVariable = 'example value';

$(document).ready(function() {
$(".closebtn").click(function() {
function1(someVariable, function() {
function2(someOtherVariable);
});
});


function function1(param, callback) {
console.log("Erste Funktion");
callback();
}

function function2(param) {
console.log("Zweite Funktion");
}
})

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button class="closebtn">Close</button>






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 21 '18 at 15:58









Rico KahlerRico Kahler

4,81332335




4,81332335













  • yes, it works, it was necessary to declare the variables. thank you!

    – user838531
    Nov 22 '18 at 10:05



















  • yes, it works, it was necessary to declare the variables. thank you!

    – user838531
    Nov 22 '18 at 10:05

















yes, it works, it was necessary to declare the variables. thank you!

– user838531
Nov 22 '18 at 10:05





yes, it works, it was necessary to declare the variables. thank you!

– user838531
Nov 22 '18 at 10:05




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53415319%2fjavascript-callback-functions-not-executed%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Xamarin.form Move up view when keyboard appear

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Anylogic : not able to use stopDelay()