From: <sli...@re...> - 2009-02-08 11:29:39
|
Hi I have just started using HtmlUnit and have found it excellent so far. I have come across a problem that I hope someone might be able to help me out with. I searched the archives and the web and have not had any luck. The actual error may be from the rhino libraries but I thought I would try here first in case it was something I was doing wrong with HtmlUnit. The stack trace is as follows (the code that generates it is down further) Exception in thread "HtmlUnit Managed Thread #6 for WebWindow : XMLHttpRequest.send" org.mozilla.javascript.EcmaError: TypeError: Cannot find default value for object. (script in http://webhost/Reporter/ from (13, 32) to (106, 10)#38) at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3654) at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3632) at org.mozilla.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3660) at org.mozilla.javascript.ScriptRuntime.typeError1(ScriptRuntime.java:3672) at org.mozilla.javascript.ScriptableObject.getDefaultValue(ScriptableObject.java:780) at org.mozilla.javascript.ScriptableObject.getDefaultValue(ScriptableObject.java:699) at org.mozilla.javascript.ScriptRuntime.toString(ScriptRuntime.java:724) at org.mozilla.javascript.ScriptRuntime.notFunctionError(ScriptRuntime.java:3741) at org.mozilla.javascript.ScriptRuntime.getPropFunctionAndThisHelper(ScriptRuntime.java:2247) at org.mozilla.javascript.ScriptRuntime.getPropFunctionAndThis(ScriptRuntime.java:2214) at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:3143) at script(script in http://webhost/Reporter/ from (13, 32) to (106, 10):38) at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:2487) at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:164) at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:398) at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.doTopCall(HtmlUnitContextFactory.java:192) at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3065) at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:162) at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:472) at com.gargoylesoftware.htmlunit.javascript.host.XMLHttpRequest.setState(XMLHttpRequest.java:142) at com.gargoylesoftware.htmlunit.javascript.host.XMLHttpRequest.doSend(XMLHttpRequest.java:413) at com.gargoylesoftware.htmlunit.javascript.host.XMLHttpRequest.access$000(XMLHttpRequest.java:54) at com.gargoylesoftware.htmlunit.javascript.host.XMLHttpRequest$1.run(XMLHttpRequest.java:361) at org.mozilla.javascript.Context.call(Context.java:515) at org.mozilla.javascript.ContextFactory.call(ContextFactory.java:507) at com.gargoylesoftware.htmlunit.javascript.host.XMLHttpRequest$2.run(XMLHttpRequest.java:367) at java.lang.Thread.run(Unknown Source) at com.gargoylesoftware.htmlunit.ThreadManager$1.run(ThreadManager.java:116) The javascript on the page that triggers the error is as follows Obviously parArr is an array of parameters and callback is the name of the function that will be called when the ajax request returns. createXMLHttpRequest() returns a browser compatible Ajax object which in this case should be XMLHttpRequest. function ajax(parArr, callback) { var http = createXMLHttpRequest(); var params = ""; for (var i=0; i<(parArr.length-1); i++) { params = params + parArr[i]+"&"; } params = params + parArr[parArr.length-1]; http.open("POST", "/Reporter/", true); http.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); http.setRequestHeader("Content-length", params.length); http.setRequestHeader("Connection", "close"); http.onreadystatechange = function() {//Call a function when the state changes. if(http.readyState == 4 && http.status == 200) { this.callbackFunction(http.responseText); } } this.callbackFunction = callback || function () { alert("Missing callback function!")}; http.send(params); } >From what I can determine the ampersand in the parameters is causing the problem, when I modify the request to pass only one parameter (e.g. no ampersand) it is successful. Any help or hints would be most appreciated. I hope I have provided enough information. Thanks |