0

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

2
  • 3
    results.tracks.foreach isn't a function. If it's supposed to be an array, it should be forEach Commented Sep 29, 2014 at 18:16
  • 1
    Make sure to post the full error message and context in the future. Commented Sep 29, 2014 at 18:24

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

thanks! removing the parenthesis however moves the function expected error to the getTracksByUser call
Move the function definition before you attempt to use it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.