That code looks fine - try testing from within a web page off of the server - this sounds like the sandbox is doing something odd to me.