Ticket #8110 (new defect)
dojo.io.iframe.send in one form with a submit button
| Reported by: | Zebulon | Owned by: | anonymous |
|---|---|---|---|
| Priority: | high | Milestone: | tbd |
| Component: | General | Version: | 1.2.0 |
| Severity: | major | Keywords: | |
| Cc: |
Description
- Imagine you want to upload a file via "browse" button. When 'onchange' event is triggered, sendForm function is called and upload the file by triggering this action "/funala-web/ajax/imageUpload.action"
Upload successfully work, i got a response from my servlet in a textarea like this: <textarea> { "id" : "27620", "name" : "js3250.dll", "mimetype" : "application/octet-stream", "size" : "681 Ko" } </textarea>
So ok, the file is uploaded on the server. Now you want, by clicking on "submit" button target : "redirectToHome.action" This action aims at redirect the user away.
When i click on submit, the browser attempt to redirect the user away but fail. It seems that a Javascript error block the redirection. You can see a screenshot of the failure with httpfox : http://zaibe.ath.cx/dojo.jpg
Here is the code u can quickly reproduce the bug.
<script type="text/javascript" src="/funala-web/js/dojo-release-1.2.0/dojo/dojo.js"></script>
<form method="post" id="testAjaxId" enctype="multipart/form-data" action="redirectToHome.action" validate="false">
<input type="file" name="upload" id="upload_1" onchange="sendForm()"/> <input type="submit"/>
</form>
<script type="text/javascript">
function sendForm() {
dojo.require("dojo.io.iframe"); dojo.addOnLoad(function() {
dojo.io.iframe.send({
url: "/funala-web/ajax/imageUpload.action", method: "post", handleAs: "text", form: dojo.byId("testAjaxId"), handle: function(data){
console.debug("Uploaded")
}, error: function (error) {
//alert ("Uknown error has occurred:\n" +error);
}
});
});
} </script>
If i use two forms, upload and redirection work like a charm. Here is the code with two forms.
<form id="uploadForm" method="post" enctype="multipart/form-data" > <input type="file" name="upload" id="upload_1" onchange="sendForm()"/> </form>
<form id="submitForm" method="post" action="redirectToHome.action" validate="false"> <input type="submit"/> </form>
<script type="text/javascript" src="/funala-web/js/dojo-release-1.2.0/dojo/dojo.js"></script>
<script type="text/javascript">
function sendForm() {
console.debug("sendFormTriggered");
dojo.require("dojo.io.iframe"); dojo.addOnLoad(function() {
dojo.io.iframe.send({
url: "/funala-web/ajax/imageUpload.action", method: "post", handleAs: "text", form: dojo.byId("uploadForm"), handle: function(data){
console.debug("Uploaded");
}, error: function (error) {
//alert ("Uknown error has occurred:\n" +error);
}
});
});
} </script>
do you have any idea why its not working with one form ? is it really a bug ?
Florent Valdelievre