I found the problem. I moved it ahead of some other code and then it worked. Apparently, the other code wasn't working which caused the page to freeze. However, I now have a new problem. I have:
var page = new XMLHttpRequest();
Putting $("p#test").html("AAAA"); ahead of page.open is what makes it work, so page.open seems to be causing the page to freeze. How do I get page.open to work properly?