Hi I'm looking for a way to render an XML document, that I retrieve using ajax, to a new browser window.
I am using JQuery's ajax() function to post JSON data to an MVC controller. The controller returns XML as a string.
I am using window.open() to create a new window in javascript and set the documents content by calling.
newwindow.document.clear();
newwindow.document.
newwindow.document.write(jqXHR.responseText);
newwindow.document.close();
(Where jqXHR.responseText is the XML returned from the ajax() call.)
The new window opens as expected and if I view source on the page I see my XML. BUT (you knew one was coming) nothing appears in the browser window. Obviously if I save the page source to disk and open the output is rendered as expected.
Can anyone suggest a solution?
Just to re-iterate my main goal is to render an XML document (obtained through ajax call) to a new window.
I should also add that I would like to see the output transformed by an XSLT. My XML has this processing instruction.
Many Thanks
Edit--------------------------- THE SOLUTION I WENT WITH -------------------------
Thanks for everyone's comments and suggestions.
The solution that I ended up going with was to have a form with target="_blank" I then wrote the JSON to the form as a hidden field, and posted it to my controller which returned the XML (constructed from the JSON). When the XML was returned from the response the browser marked it up as expected. I guess this is not an answer to the original question. But Gabby has a solution below.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…