1

i've been getting a html page using ajax, then open a new window and writting the html data into this new window.

Its working fine on IE 8... however, Chrome is messing the encoding..

My code:

 $('#bo').submit(function( event ) {

             $.ajax({
                url : "./home.html",
                cache : false,
                type: 'POST',
                dataType : "html",
            }).done(function(data) {
                 var doc = window.open("", "_blank");
                 doc.document.write(data);
                 doc.document.close();
                });

             event.preventDefault();
            return false;
        });

The data string contains this html:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE">
</head>

<body>
    <div id="ui-master">
        <div id="ui-header">
         </div>
   </div>
</body>
</html>

Can anyone give me a direction here? Im a bit confused why it works on IE but not on Chrome.. When the dom is ready, im loading some jquery features, like jquery dialogs, jquery growl messages and knockout stuff to fill the page, not sure if its relevant.

The strange fact is that if I change the code do something like replace my window html instead of opening a new popup.. the encoding will work fine =( Thanks

ddacrs
  • 123
  • 1
  • 9
  • Can you post the contents of `data` here as well? – stackErr Dec 09 '14 at 16:47
  • 1
    `document.write` is commonly held to be bad practice: you might wish to investigate alternative methods for DOM manipulation. (more here: http://stackoverflow.com/questions/802854/why-is-document-write-considered-a-bad-practice) – msturdy Dec 09 '14 at 17:12

1 Answers1

0

Although I wouldn't recommend to use document.write, and I'm not sure this will solve your problem, you can try forcing the content encoding on the $.ajax function like this:

$.ajax({
                url : "./home.html",
                cache : false,
                contentType: "text/html;charset=UTF-8"
                type: 'POST',
                dataType : "html",
            });
jorge.alonso
  • 269
  • 2
  • 5