B
B
Bur Ov2016-04-20 23:35:42
JavaScript
Bur Ov, 2016-04-20 23:35:42

Uncaught ReferenceError: *** is not defined?

When the script is run, it displays an error in the console: Uncaught ReferenceError: callbackFunc is not defined what is the problem?

<div id='feedback'></div>
<input type='button' value='Test' onclick='GetUserName();'/>

VK.init({
    apiId: 5426330
  }); 

var userId = 339190723;
  
var GetUserName = function () {
VK.api('friends.get', {'user_id' : userId}, function(data) { 
  for (var i = 0, l = data.response.length; i < l; i++) {
        var script = document.createElement('SCRIPT');
    script.src = "https://api.vk.com/method/friends.get?user_id="+ data.response[i] +"&v=5.50&callback=callbackFunc";
    document.getElementsByTagName("head")[0].appendChild(script);
      function callbackFunc(result) { 
    if (result.response.items.indexOf(userId) != '-1') {
    document.getElementById('feedback').innerHTML = data.response[i];
        }
      }
    }
  });
};

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey, 2016-04-20
@alsopub

The callback function is not defined, obviously.
It's hard to say exactly from the input data.
UPD.
Try moving the definition of the callbackFunc function higher, since at the time of connecting the script https://api.vk.com/method/friends.get?user_id=...&... this function does not yet exist.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question