Note that there are some explanatory texts on larger screens.

plurals
  1. PONode.js callback confusion
    text
    copied!<p>I am trying to implement an autocompleter on a nodejs app using nowjs. </p> <pre><code>everyone.now.sendAutocomplete = function(search) { var response = getAutocomplete(search); console.log("response"); console.log(response); }; </code></pre> <p>which calls:</p> <pre><code>function getAutocomplete(search) { console.log(search); var artist = new Array(); request({uri: 'http://musicbrainz.org/ws/2/artist/?query=' + search + '&amp;limit=4', headers: "Musicbrainz Application Version 1"}, function(error, response, body) { par.parseString(body, function(err, result) { var count = result['artist-list']['@']['count']; var artists = result['artist-list']['artist']; // var artist = new Array(); if (count &gt; 1) { artists.forEach(function(a) { var att = a['@']; var id = att['id']; var name = a['name']; var dis = a['disambiguation']; if (dis) { var display = name + " (" + dis + " )"; } else { display = name; } artist.push({'id':id, 'name': name, 'disambiguation':dis, 'label':display, 'value':name, 'category':"Artists"}); }); //everyone.now.receiveResponse(artist); console.log("artist"); console.log(artist); return artist; } else { console.log(artists); var att = artists['@']; var id = att['id']; var name = artists['name']; var dis = artists['disambiguation']; var resp = [{'id':id, 'name': name, 'disambiguation':dis, 'label':name, 'value':name, 'category':"Artists"}]; return resp; // everyone.now.receiveResponse([{'id':id, 'name': name, 'disambiguation':dis, // 'label':name, 'value':name, 'category':"Artists"}]); } }); }); } </code></pre> <p>However, console.log(response) says that response is undefined. I am new to node so the answer is probably simple, but still can't figure it out. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload