JavaScript callback functions not executed
up vote
0
down vote
favorite
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 |
up vote
0
down vote
favorite
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 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 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 at 15:29
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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 at 15:26
user838531
12719
12719
Add a button with the classclosebtn
and initialising the variable, this code works. What error are you getting?
– George
Nov 21 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 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 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 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 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 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 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 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 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 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 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 at 15:29
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
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 at 10:05
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
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 at 10:05
add a comment |
up vote
1
down vote
accepted
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 at 10:05
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
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 at 15:58
Rico Kahler
4,33631932
4,33631932
yes, it works, it was necessary to declare the variables. thank you!
– user838531
Nov 22 at 10:05
add a comment |
yes, it works, it was necessary to declare the variables. thank you!
– user838531
Nov 22 at 10:05
yes, it works, it was necessary to declare the variables. thank you!
– user838531
Nov 22 at 10:05
yes, it works, it was necessary to declare the variables. thank you!
– user838531
Nov 22 at 10:05
add a comment |
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 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 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 at 15:29