1

I'm working on an Ajax project. Everything on my page works, including this section:

var data =  {
    doc:     "sample", 
    action:  "updatemsg", 
    dbid:    97, 
    message: "text"
};

$.ajax({
    url:     ANNOTATION_ENDPOINT,
    data:    data,
    success: console.log,
    error:   console.log
});

However, on every request, it throws this error:

Uncaught TypeError: Illegal invocation    jquery.js:974
    fire                                  jquery.js:974
    self.fireWith                         jquery.js:1084
    done                                  jquery.js:7803
    callback                              jquery.js:8518

and the console.log calls are never made. ANNOTATION_ENDPOINT is a valid URL; my other functions use it with no problem.

I've broken down the problem to this small section but I'm baffled here. Any insight?

Ryan Kennedy
  • 3,275
  • 4
  • 30
  • 47
  • 1
    Related: http://stackoverflow.com/questions/8159233/typeerror-illegal-invocation-on-console-log-apply – Rob W Mar 09 '13 at 17:16

1 Answers1

1

the log function expects its context to be the console object not an jqXHR so try

$.ajax({
    url:     ANNOTATION_ENDPOINT,
    data:    data,
    success: console.log.bind(console),
    error:   console.log.bind(console)
});
Musa
  • 96,336
  • 17
  • 118
  • 137