Using an IIFE always gives me a 'callback-function-name' is not defined error. A regular load function on the other hand works fine. Any ideas appreciated guys...!
<script type="text/javascript">
(function() {
function myfeed(feed) {
alert(feed);
}
var tags = 'potatoes';
var script = document.createElement('script');
script.src = 'http://api.flickr.com/services/feeds/photos_public.gne?format=json&jsoncallback=myfeed&tags=' + tags;
document.head.appendChild(script);
}());
</script>
jsoncallback=myfeed
is going to look for a global function. Currently, myfeed
is scoped inside of the IIFE.
If you want to make it globally available, you need to do something like this:
function myfeed(feed) {
alert(feed);
}
(function() {
var tags = 'potatoes';
var script = document.createElement('script');
script.src = 'http://api.flickr.com/services/feeds/photos_public.gne?format=json&jsoncallback=myfeed&tags=' + tags;
document.head.appendChild(script);
}());
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.