Your example javascript looks like jquery code. Maybe you just need to import the jquery library ...
For how to deal with XMLHttpRequest
in Rhino, see this Q&A: XMLHttpRequest in Rhino?.
As Joachim points out, jquery
, the DOM
APIs and XMLHttpRequest
are not part of the ECMAScript specification.