I take it what you want to do is insert "Content" into divId, and then
fire an alert(). The problem you have is that the value of data is
nothing but a simple string. Your callback has to know what to do with

IIRC, Dojo has a function that will execute all <script> tags within a
string, so you could certainly call that to get the alert() to fire... but
that doesn't help you put the content in the DOM.

I suggest what you should do instead is have your response returned a bit
differently. Something as simple as this:


Then in your callback you do:

var a = data.split("~~");
document.getElementById(divId).innerHTML = a[0];

The response could also be JSON:

{ divContent: "Content", msg : "test" }

Then you do:

data = eval(data);
document.getElementById(divId).innerHTML = data.divContent;


Frank W. Zammetti
Author of "Practical Ext JS Projects with Gears" (coming soon)
and "Practical Dojo Projects"
and "Practical DWR 2 Projects"
and "Practical JavaScript, DOM Scripting and Ajax Projects"
and "Practical Ajax Projects with Java Technology"
(For info: apress.com/book/search?searchterm=zammetti&act=search)
All you could possibly want is here: zammetti.com
On Mon, March 30, 2009 10:27 am, Tedy Marcos Colombini wrote:
Hi there,

After being able to submit an ajax form request using javascript, I am
in the second (and last) problem. The response contains an inline script
which I wanna execute when the it is rendered. I am using Struts 2.0.11
Dojo 0.4. I did some research but everything I found is incomplete.

This is the code. It works, only the alert from the response doesn't pop
out. So what I should do to make this script run?

<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<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){

<s:form id="myForm" action="example/Test.action">
<input type="button" onclick="submitForm('myForm', 'divResult')"
value="Javascript" />
<div id="divResult"></div>

This is the response from Test.action:


Thank you for your help,

Tedy Marcos Colombini

To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org

Search Discussions

Discussion Posts


Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 4 of 6 | next ›



site design / logo © 2016 Grokbase