I have a problem with a Struts2 + dojo web application that I’ve inherited. The application works in IE9 and Firefox but does not work in Chrome.
Here is the submit button code:
<button dojoType="dijit.form.Button"
type="submit"
onclick="sendRuleForm('requestSubmitForm', 'resultDiv', 'RequestSubmit.action');">Submit</button>
Here is the javascript code for the sendRuleForm function above:
function sendRuleForm(formId, id, actionNm) {
var bindArgs = {
url: actionNm,
form: document.getElementById(formId),
handleAs: "text",
load: function(data) {
document.getElementById(id).innerHTML = data;
},
error: function(data) {
alert(data);
return;
}
}
dojo.xhrPost(bindArgs);
document.getElementById(id).innerHTML = ajaxLoader;
}
I noticed that if I set breakpoints in my Java code, the web page returns with an error even before the action even completes.
Chrome Developer Tools indicate a status of cancelled for the action/request ( What does status=canceled for a resource mean in Chrome Developer Tools? )
I am using an older version of dojo 1.3.1 but updating it to the latest version did not fix the problem.
Can anyone explain this behavior and let me know how I can go about fixing this?
You can rule out the ajax / javascript bit of this error. It is either
<button type="submit"and<input type="submit"is handled differently in chromeWhat youre experiencing in the redirect to a different page is probably due to the fact that Struts Application receives a GET when you manually refresh the URL field in the new tab. Could also be due to a missing login-cookie or such.
To have a true response from the application, try put in the
targetattribute with yourformand then submit in a normal fashion (without XHR).Also, your dijit Button has an overridable function ‘onClick’, note the camelCasing. Youre setting the DOM onclick event. In this case, youre click event may get handled by the browser immediately after the dojo.xhr fires (when function returns). See this Q: Preventing form submission with Dojo
Only way, however, for this to be the case – and at same time you seeing the ‘Cancelled’ error in debug window is, if the form is loaded in a (i)frame. Otherwise the full page would refresh and network monitoring would reset. As an easy, win-win workaround, adapt the onclick attribute as follows: