You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-user@portals.apache.org by Akshay Ahooja <ak...@gmail.com> on 2006/07/06 18:42:21 UTC

Ajax URL with Struts J2

Hi,

I am using Struts Bridge in J2, with AJAX components.

For regular links, using <html:link works out fine, however for Ajax, I have
a validate function:

    function validate()
    {

        var idField= document.getElementById("taskid");
        var url = "validate?id=" + escape(idField.value);
        if (window.XMLHttpRequest) {
            req = new XMLHttpRequest();
        }
        else {
            req = new ActiveXObject("Microsoft.XMLHTTP");
        }


        req.open("GET", url, true);
        req.onreadystatechange=callback;
        req.send(null);
    }

This validate function has a url that it uses. It works fine as a WebApp but
gives a javascript "Object Expected" error when ran in J2.I assume this is
because of the URL itself. How do I call this URL within this function? (Is
GET ok or does it need to be POST? - I do not wish to use POST as it will
limit my application, and plus this does not affect the server side
application state.)

My URI in web.xml is:

     <servlet>
        <servlet-name>validate</servlet-name>
        <servlet-class>com.svvc.rap.ValidateServlet</servlet-class>
        <url-pattern>*.do</url-pattern>
    </servlet>
    <servlet-mapping>
        <servlet-name>validate</servlet-name>
        <url-pattern>/validate</url-pattern>
    </servlet-mapping>

Re: Ajax URL with Struts J2

Posted by Akshay Ahooja <ak...@gmail.com>.
I got that to work by changing the url to the full path:

    function validate()
    {

        var idField=document.getElementById("taskid");
        var url = "http://smith-xp:8080/rapsheet/validate?id=" + escape(
idField.value);
        ....


However this now does not work in Firefox - only in IE.

Any ideas where Firefox would be picking up teh problem?

I pinpointed the problem to occur at: req.open("GET", url, true);
No alerts after this line are reached.

Thanks,

Akshay


On 7/6/06, Akshay Ahooja <ak...@gmail.com> wrote:
>
> Hi,
>
> I am using Struts Bridge in J2, with AJAX components.
>
> For regular links, using <html:link works out fine, however for Ajax, I
> have a validate function:
>
>     function validate()
>     {
>
>         var idField= document.getElementById("taskid");
>         var url = "validate?id=" + escape(idField.value);
>         if (window.XMLHttpRequest) {
>             req = new XMLHttpRequest();
>         }
>         else {
>             req = new ActiveXObject("Microsoft.XMLHTTP");
>         }
>
>
>         req.open("GET", url, true);
>         req.onreadystatechange=callback;
>         req.send(null);
>     }
>
> This validate function has a url that it uses. It works fine as a WebApp
> but gives a javascript "Object Expected" error when ran in J2.I assume
> this is because of the URL itself. How do I call this URL within this
> function? (Is GET ok or does it need to be POST? - I do not wish to use POST
> as it will limit my application, and plus this does not affect the server
> side application state.)
>
> My URI in web.xml is:
>
>      <servlet>
>         <servlet-name>validate</servlet-name>
>         <servlet-class>com.svvc.rap.ValidateServlet</servlet-class>
>         <url-pattern>*.do</url-pattern>
>     </servlet>
>     <servlet-mapping>
>         <servlet-name>validate</servlet-name>
>         <url-pattern>/validate</url-pattern>
>     </servlet-mapping>
>
>
>
>
>