user3576112
user3576112

Reputation: 67

Javascript Foreach Function Expected

I am using a function which takes a callback paramater to which im passing my own function. I'm however getting the error function expected

GpsGate.Server.MyService.getTracksByUser(groupName, user.username, getTracksByUser_callback());

function getTracksByUser_callback(result)
{
  var responseData = '<response>';
  result.tracks.foreach( //error on this line
    function addTrack(track) {
      responseData += '<track>';
       //ommited
      responseData += '</track>';
     }
  );
  responseData += '</response>';
  response.body = responseData;
}

looking at examples http://msdn.microsoft.com/en-us/library/ie/ff679980(v=vs.94).aspx im unsure why it is not working

Upvotes: 0

Views: 428

Answers (1)

Mike Robinet
Mike Robinet

Reputation: 843

You are not passing the function, you are executing the function and passing the result.

Remove the parenthesis:

GpsGate.Server.MyService.getTracksByUser(groupName, user.username, getTracksByUser_callback);

There is also the error Matt Burland pointed out in the comments, where it should be forEach not foreach.

Upvotes: 3

Related Questions