Menu

#990 ScriptException with PUT AJAX Requests in jQuery

Latest SVN
closed
None
5
2012-10-21
2009-11-25
thilo
No

Hi i get a ScriptException when I run a PUT AjaxRequest with the 2.7 Snapshot from 09. Nov.

$.ajax({
url: "testhost.com"
type: "PUT"
data: "test"
});

Discussion

  • Lena Herrmann

    Lena Herrmann - 2009-11-26

    +1 for fixing this!

     
  • Marc Guillemot

    Marc Guillemot - 2009-11-26

    Can you provide the stacktrace as well as a minimal example (ie the html code)?

     
  • thilo

    thilo - 2009-11-29

    Sorry took me a while to get back to this. Here is the StackTrace:
    com.gargoylesoftware.htmlunit.ScriptException: Exception invoking jsxFunction_send (Culerity::CulerityException)
    com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine.java:526:in run' net/sourceforge/htmlunit/corejs/javascript/Context.java:537:incall'
    net/sourceforge/htmlunit/corejs/javascript/ContextFactory.java:538:in call' com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine.java:456:incallFunction'
    com/gargoylesoftware/htmlunit/html/HtmlPage.java:893:in executeJavaScriptFunctionIfPossible' com/gargoylesoftware/htmlunit/javascript/host/EventListenersContainer.java:155:inexecuteEventListeners'
    com/gargoylesoftware/htmlunit/javascript/host/EventListenersContainer.java:208:in executeBubblingListeners' com/gargoylesoftware/htmlunit/javascript/host/Node.java:645:infireEvent'
    com/gargoylesoftware/htmlunit/html/HtmlElement.java:887:in run' net/sourceforge/htmlunit/corejs/javascript/Context.java:537:incall'
    net/sourceforge/htmlunit/corejs/javascript/ContextFactory.java:538:in call' com/gargoylesoftware/htmlunit/html/HtmlElement.java:892:infireEvent'
    com/gargoylesoftware/htmlunit/html/HtmlElement.java:1248:in click' com/gargoylesoftware/htmlunit/html/HtmlElement.java:1212:inclick'
    com/gargoylesoftware/htmlunit/html/HtmlElement.java:1179:in `click'

     
  • thilo

    thilo - 2009-11-29

    And here is a minimal html file to reproduce this:

    <html>
    <head>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js">
    </script>
    </head>
    <script type="text/javascript" charset="utf-8">
    $(function(){
    $("#click_me").bind('click', function(){
    $.ajax({url: "/",type: "PUT",data: "test"});
    });
    });
    </script>
    <body>
    ClickMe
    </body>
    </html>

     
  • Ahmed Ashour

    Ahmed Ashour - 2009-11-30

    Hello,

    The alert '/' is trigered as exactly done in real browsers, you can ignore the error reported happens with IE simulation only, not with FF:

    [main] ERROR com.gargoylesoftware.htmlunit.javascript.StrictErrorReporter - runtimeError
    : message=[The data necessary to complete this operation is not yet available.] sourceName=[http://localhost/htmlunit/jquery.js] line=[3078] lineSource=[null] lineOffset=[0]

    Please re-open if you have a functional issue.

     
  • thilo

    thilo - 2009-11-30

    Hi asashour is your comment related to the above issue? Because I don't see what this has to do with alert.

     
  • Ahmed Ashour

    Ahmed Ashour - 2009-11-30

    Hi,

    Oh, since I was offline which I verified thi case, I used a 'patched' jquery .js, which made the 'alert'.

    Anyhow, your test case does not trigger anything in real IE, can you modify it so that an expected result does not occur in HtmlUnit?

     
  • thilo

    thilo - 2009-12-05

    Sorry, took me a while again to get back.

    Here a modified version of the ajax call which should show an alert message on completion. One more thing to note maybe is that i run HTML Unit as a Firefox 3 browser.

    <html>
    <head>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js">
    </script>
    </head>
    <body>
    <script type="text/javascript" charset="utf-8">
    $(function(){
    $("#click_me").bind('click', function(){
    $.ajax({url: "test.html",type: "PUT", complete: function () {
    alert("hi");
    }
    });
    return false;
    });
    });
    </script>

    ClickMe
    </body>
    </html>

     
  • Ahmed Ashour

    Ahmed Ashour - 2009-12-09

    [JavaScript Job Thread 1] ERROR com.gargoylesoftware.htmlunit.javascript.background.JavaScriptJobManagerImpl - Job run failed with unexpected RuntimeException: The content cannot be null
    java.lang.IllegalArgumentException: The content cannot be null
    at org.apache.commons.httpclient.methods.StringRequestEntity.<init>(StringRequestEntity.java:93)
    at com.gargoylesoftware.htmlunit.HttpWebConnection.makeHttpMethod(HttpWebConnection.java:255)
    at com.gargoylesoftware.htmlunit.HttpWebConnection.getResponse(HttpWebConnection.java:97)

     
  • Ahmed Ashour

    Ahmed Ashour - 2009-12-09

    Thanks for reporting, fixed in SVN.

    Please wait after 'clicking' to get the 'alert', have a look at http://htmlunit.sourceforge.net/faq.html#AJAXDoesNotWork

     
  • thilo

    thilo - 2009-12-10

    Hi thanks for looking into this. I tested the latest svn build today. The exception is gone, but the data i send with the PUT, is gone too. I changed my example script to reproduce the effect. To check the send parameters you need some kind of backend though. When I click the link in my Browser (Firefox 3.6b4) the backend receives the parameter test=best. If I click the link through HtmlUnit no parameters are send.

    <html>
    <head>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js">
    </script>
    </head>
    <body>
    <script type="text/javascript" charset="utf-8">
    $(function(){
    $("#click_me").bind('click', function(){
    $.ajax({url: "test.html",type: "PUT", data: "test=best", complete: function () {
    alert("hi");
    }
    });
    return false;
    });
    });
    </script>

    ClickMe
    </body>
    </html>

     
  • Daniel Gredler

    Daniel Gredler - 2009-12-10

    Re-opening as per user's comment.

     
  • Ahmed Ashour

    Ahmed Ashour - 2009-12-12

    Aha, now I see the empty body.

    There is a local fix, to be committed soon.

     
  • Ahmed Ashour

    Ahmed Ashour - 2009-12-30

    Thanks for reporting, fixed in SVN, please get latest snapshot from http://build.canoo.com/htmlunit/artifacts, and advise if you still have an issue

     
  • Lena Herrmann

    Lena Herrmann - 2010-01-29

    Works like a charme. Thank you!

     

Log in to post a comment.