I am experimenting with jQuery and I try to use the $.getJSON
function
I red that "A reference to a function declaration could equally be provided as the callback". So instead of an anonymous function, I use a reference to a function declaration like this
$('#letter-b').click(function(e) {
e.preventDefault();
$.getJSON('b.js', outside(data));
});
function outside (data){alert(data);}
I get no alert. Instead I get Uncaught ReferenceError: data is not defined
What am I missing? Is it my syntax?
Thanks in advance
You must give the reference to your function. Like this :
$('#letter-b').click(function(e) {
e.preventDefault();
$.getJSON('b.js', outside);
});
If you write outside(data)
, you just execute your function.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.