JavaScript callback functions not executed
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
add a comment |
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
Add a button with the classclosebtn
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 intofunction1
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 comment |
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
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
javascript callback
asked Nov 21 '18 at 15:26
user838531user838531
13419
13419
Add a button with the classclosebtn
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 intofunction1
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 comment |
Add a button with the classclosebtn
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 intofunction1
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
add a comment |
1 Answer
1
active
oldest
votes
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>
yes, it works, it was necessary to declare the variables. thank you!
– user838531
Nov 22 '18 at 10:05
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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>
yes, it works, it was necessary to declare the variables. thank you!
– user838531
Nov 22 '18 at 10:05
add a comment |
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>
yes, it works, it was necessary to declare the variables. thank you!
– user838531
Nov 22 '18 at 10:05
add a comment |
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>
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>
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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