I wrote a cross-domain, as it seemed at first glance, "Ajax":

function MyAjax (url, param, callback, getXml) { if (!document.createElement) return; var frame = myAjaxCreateIFrame(); var getIFrameXML = getIFrameXML; frame.onSendComplete = function() {callback(getIFrameXML(frame, !getXml));}; if (param) { var isOne = true; for (var attr in param) { url += (isOne ? "?" : "&") + attr + "=" + param[attr]; isOne = false; }; }; frame.src = url; } function myAjaxCreateIFrame () { var id = 'if' + Math.floor(Math.random() * 99999); var div = document.createElement('div'); div.innerHTML = "<iframe style=\"display:none\" src=\"about:blank\" id=\""+id+"\" name=\""+id+"\" onload=\"sendComplete('"+id+"')\"></iframe>"; document.body.appendChild(div); return document.getElementById(id); } function sendComplete (id) { var iframe = document.getElementById(id); if (iframe.onSendComplete && typeof(iframe.onSendComplete) == 'function') iframe.onSendComplete(); } function getIFrameXML (iframe, getText) { var doc=iframe.contentDocument; if (!doc && iframe.contentWindow) doc=iframe.contentWindow.document; if (!doc) doc=window.frames[iframe.id].document; if (!doc) return null; if (doc.location=="about:blank") return null; if (doc.XMLDocument) doc=doc.XMLDocument; return getText ? doc.body.innerText : doc; } 

Chrome works, although it throws an error:

 Resource interpreted as Document but transferred with MIME type application/json: 

And in IE generally offers to download the file!

How to remove this error and force not to consider the data coming from the server in IE as a file, but just open it in IFreme?

PS Such frills are undertaken because Ajax (even through proxy) does not work for JSON in thin client 1C. Who faced and decided - help ...



    1 answer 1

    The server must transfer the content type, otherwise IE considers that the data stream is transmitted and offers to save it as a file since neither JS nor Flash requested it ...

    • Thank you, I have already decided to refuse such requests - switched to proxy.cgi - t1nk