From: Ahmed A. <asa...@ya...> - 2009-02-12 10:09:42
|
Dear Sling, Strangely, no errors from SVN version!! Please use latest snapshot from http://build.canoo.com/htmlunit/artifacts, and advise. Yours, Ahmed ________________________________ From: Sling Gatsby <sli...@re...> To: htm...@li... Sent: Thursday, February 12, 2009 12:13:14 PM Subject: Re: [Htmlunit-user] Ajax javascript errors Hi Sorry for the delay. Below is a simple class and html file that gives me the error I described. You can set the url for the post to anything it fails before the request is sent. I hope this is enough info. TestCase.class ----------------------------------------- package junittests; import java.net.URL; import org.junit.Test; import com.gargoylesoftware.htmlunit.HttpMethod; import com.gargoylesoftware.htmlunit.WebRequestSettings; import com.gargoylesoftware.htmlunit.html.HtmlPage; public class TestCase { @Test public void test() { try { WebRequestSettings reqSet = new WebRequestSettings(new URL( "http://localhost/test.html"), HttpMethod.POST); HtmlPage page = ReporterTestHelper.webClient.getPage(reqSet); Thread.sleep(5 * 1000); System.err.println(page.getWebResponse().getContentAsString()); } catch (Exception e) { e.printStackTrace(); } } } ----------------------------------------- test.html ----------------------------------------- <html> <head> <title>Test Case</title> <script type="text/javascript"> function createXMLHttpRequest() { if (typeof XMLHttpRequest != "undefined") { return new XMLHttpRequest(); } else if (typeof ActiveXObject != "undefined") { return new ActiveXObject("Microsoft.XMLHTTP"); } else { throw new Error("XMLHttpRequest not supported"); } } 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", "/test.html", 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); } function getObjectByID(elmID) { if(document.getElementById) {elmID = document.getElementById(elmID);} else if(document.all) {elmID = document..all[elmID];} else if(document.layers) {elmID = this._getLayer(elmID);} else if(document.forms) { if(document.forms[elmID]) {elmID = document.forms[elmID];} else { for(var i=0; i<document.forms.length; i++) { if(document.forms[i][elmID]) { elmID = document.forms[i][elmID]; break; } } } } else {elmID = null;} return elmID; } function callback(data){ var obj = getObjectByID('testbtn'); obj.disabled=false; } ajax(['ACTION=99','TEST=22'], callback); </script> </head> <body> Test Case<br /> <button disabled="true" id="testbtn">Get It</button> </body> </html> ----------------------------------------- Thanks Sling |