You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Tedy Marcos Colombini <te...@gmail.com> on 2009/03/27 11:55:59 UTC
problems with struts and dojo
Hi guys, sorry for the previous email. I pressed some shortcut by accident.
I am trying to generate an ajax request with javascript. The code is very
simple but it doesn't work.
The message I get is: dojo.xhrGet is not a function (in Firefox error
console).
With a <s:form> and <s:submit>, I am able to generate a request.
So I am wondering if there is some configuration trick to be done when using
the javascript approach.
I am using Struts 2.0.11.
Thanks for your help.
Tedy.
This is the code that doesn't work:
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<s:head theme="ajax" debug="true"/>
<script type="text/javascript">
function submitForm() {
var kw = {
url: "example.HelloWorld!execute.action",
handleAs:"text",
load: function(response){
dojo.byId('divResult').innerHTML = response;
},
error: function(data){
console.debug("An error occurred: ", data);
},
timeout: 2000,
};
dojo.xhrGet(kw);
}
</script>
</head>
<body>
<input type="button" onclick="submitForm()" value="Javascript" />
<s:div id="divResult"></s:div>
</body>
</html>
--
Tedy Marcos Colombini
Re: problems with struts and dojo
Posted by Tedy Marcos Colombini <te...@gmail.com>.
Hi,
I changed the dojo.xhrGet call for a dojo.io.bind call as suggested by
Andras and now it works. Please find the corrected code below.
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<s:head theme="ajax" debug="true"/>
<script type="text/javascript">
function submitForm(formId, divId) {
var kw = {
formNode: dojo.byId(formId),
mimetype: "text/plain",
method: "post",
transport: "XMLHTTPTransport",
load: function(type, data, http, kwArgs){
dojo.byId(divId).innerHTML = data;
},
error: function(type, error, http){
alert(error);
}
};
dojo.io.bind(kw);
}
</script>
</head>
<body>
<s:form id="myForm" action="example/HelloWorld.action">
<input type="button" onclick="submitForm('myForm', 'divResult')"
value="Javascript" />
</s:form>
<s:div id="divResult"></s:div>
</body>
</html>
On Fri, Mar 27, 2009 at 2:19 PM, Andras Balogh <an...@reea.net> wrote:
> Hi,
>
> The problem is most probably that dojo.xhrGet is not available in the dojo
> version that comes
> with Struts 2.0.x ( dojo 0.4)
> You must make sure to use only dojo functions that are avail. in ver. 0.4.
> See here more details:
>
>
> http://dojotoolkit.org/forum/dojo-0-4-x-legacy/dojo-0-4-x-support/whick-package-xhrget-available-0-4
>
> BR,
> Andras
>
>
> Tedy Marcos Colombini wrote:
>
>> Hi guys, sorry for the previous email. I pressed some shortcut by
>> accident.
>>
>> I am trying to generate an ajax request with javascript. The code is very
>> simple but it doesn't work.
>> The message I get is: dojo.xhrGet is not a function (in Firefox error
>> console).
>>
>> With a <s:form> and <s:submit>, I am able to generate a request.
>>
>> So I am wondering if there is some configuration trick to be done when
>> using
>> the javascript approach.
>>
>> I am using Struts 2.0.11.
>>
>> Thanks for your help.
>>
>> Tedy.
>>
>>
>> This is the code that doesn't work:
>>
>> <%@ page contentType="text/html; charset=UTF-8" %>
>> <%@ taglib prefix="s" uri="/struts-tags" %>
>> <html>
>> <head>
>> <s:head theme="ajax" debug="true"/>
>> <script type="text/javascript">
>> function submitForm() {
>> var kw = {
>> url: "example.HelloWorld!execute.action",
>> handleAs:"text",
>> load: function(response){
>> dojo.byId('divResult').innerHTML = response;
>> },
>> error: function(data){
>> console.debug("An error occurred: ", data);
>> },
>> timeout: 2000,
>> };
>> dojo.xhrGet(kw);
>> }
>> </script>
>> </head>
>>
>> <body>
>> <input type="button" onclick="submitForm()" value="Javascript" />
>> <s:div id="divResult"></s:div>
>> </body>
>> </html>
>>
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
--
Tedy Marcos Colombini
Re: problems with struts and dojo
Posted by Andras Balogh <an...@reea.net>.
Hi,
The problem is most probably that dojo.xhrGet is not available in the
dojo version that comes
with Struts 2.0.x ( dojo 0.4)
You must make sure to use only dojo functions that are avail. in ver. 0.4.
See here more details:
http://dojotoolkit.org/forum/dojo-0-4-x-legacy/dojo-0-4-x-support/whick-package-xhrget-available-0-4
BR,
Andras
Tedy Marcos Colombini wrote:
> Hi guys, sorry for the previous email. I pressed some shortcut by accident.
>
> I am trying to generate an ajax request with javascript. The code is very
> simple but it doesn't work.
> The message I get is: dojo.xhrGet is not a function (in Firefox error
> console).
>
> With a <s:form> and <s:submit>, I am able to generate a request.
>
> So I am wondering if there is some configuration trick to be done when using
> the javascript approach.
>
> I am using Struts 2.0.11.
>
> Thanks for your help.
>
> Tedy.
>
>
> This is the code that doesn't work:
>
> <%@ page contentType="text/html; charset=UTF-8" %>
> <%@ taglib prefix="s" uri="/struts-tags" %>
> <html>
> <head>
> <s:head theme="ajax" debug="true"/>
> <script type="text/javascript">
> function submitForm() {
> var kw = {
> url: "example.HelloWorld!execute.action",
> handleAs:"text",
> load: function(response){
> dojo.byId('divResult').innerHTML = response;
> },
> error: function(data){
> console.debug("An error occurred: ", data);
> },
> timeout: 2000,
> };
> dojo.xhrGet(kw);
> }
> </script>
> </head>
>
> <body>
> <input type="button" onclick="submitForm()" value="Javascript" />
> <s:div id="divResult"></s:div>
> </body>
> </html>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org