Ticket #524: test2.html

File test2.html, 3.7 kB (added by andyhot@…, 3 years ago)

open this file in IE to reproduce the problem

Line 
1<html>
2<head>
3        <script type="text/javascript">
4        djConfig = { isDebug: false,
5                     baseRelativePath: "js/dojo",
6                     preventBackButtonFix: false,
7                     parseWidgets: true
8                   };
9        </script>     
10        <script type="text/javascript" src="js/dojo/dojo.js"></script> 
11</head>
12<body>       
13        <script>
14    dojo.require("dojo.io.IframeIO");               
15
16//
17// Retrieves node names from an XML node and children nodes.
18//                         
19_nodesFromXML = function(node){
20        var toxml = "";
21        if (node.nodeType==1) {
22                toxml += node.nodeName + " ";
23        }
24        if (node.childNodes) {
25                for (var i=0; i<node.childNodes.length; i++) {
26                        toxml += _nodesFromXML(node.childNodes[i]);
27                }
28        }
29        return toxml;
30}           
31               
32//
33// Retrieves text from an XML node and children nodes.
34//                         
35_textFromXML = function(node){
36        var toxml = "";
37        if (node.nodeType==3) {
38                toxml += node.nodeValue;
39        }
40        if (node.childNodes) {
41                for (var i=0; i<node.childNodes.length; i++) {
42                        toxml += _textFromXML(node.childNodes[i]);
43                }
44        }
45        return toxml;
46}
47
48//
49// Dojo's IframeIO transport is buggy on IE when the request is multipart.
50// In that case, the response xml is hidden in text nodes. This function
51// tries to get the response text and convert it to xml.
52//
53_fixIframeDataForIE = function(data) {
54        dojo.debug("Try IE fix for iframe reponse.");
55        var content = _textFromXML(data);
56        // remove doctype and first -
57        var pos1 = content.indexOf("<!DOCTYPE");
58        var pos2 = content.indexOf("- ");
59        if (pos1>=0 && pos2>pos1) {
60                content = /*content.substring(0,pos1-1) + */content.substring(pos2+1);
61                try {
62                var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
63                xmlDoc.async = false;
64                xmlDoc.loadXML(content);
65                data = xmlDoc;
66        }
67        catch (e) {}           
68        }
69        return data;
70}                         
71               
72function testMulti()
73{               
74    dojo.io.bind({
75        url: "simple.xml",
76        content: { dojoRequest: "true"},
77        formNode: document.getElementById("ajaxform"),
78        load: function(type, data, evt)
79        {
80            loadDojoResponse(type, data, evt);
81        },
82        backButton: function()
83        {
84            alert('back');
85        },
86        forwardButton: function()
87        {
88            alert('forward');
89        },
90        error: function(type, error)
91        {
92            alert("Received error response of type "
93                  + type + " with error " + error.message);           
94        },
95        mimetype: "text/xml",
96        encoding: "UTF-8",
97        method: "post",
98        multipart: true,
99        transport: "IframeTransport"
100    });                               
101}
102               
103loadDojoResponse = function(type, data, request, kwArgs)
104{           
105    alert(_nodesFromXML(data));
106               
107    var response = data.getElementsByTagName("ajax-response");   
108               
109        if (response == null || response.length < 1) {
110        alert('applying IE fix');
111        data = _fixIframeDataForIE(data);
112        alert(_nodesFromXML(data));   
113    }
114}               
115                                                         
116        </script>
117       
118        <form id="ajaxform" name="ajaxform"
119            enctype="multipart/form-data" onsubmit="testMulti();return false;">
120            <input type="file" name="f"><br><br>
121            <input type="submit" value="Test Multipart IframeTransport" id="ajaxsubmit">
122        </form>
123       
124        No need to select a file - just press the 'Test Multipart IframeTransport' button.<br>
125        You'll then see a javascript alert with the tags contained in the response.<br>
126        However, IE shows the contents of the hidden IFrame.         
127        <br>
128        <a href="simple.xml">View expected xml response</a>
129         
130
131</body>
132
133</html>