'Error: uncaught exception: [Exception... "An invalid or illegal string was specified"

This two errors I get in the Firefox error console:

Error: Incorrect document format
Source file: 
Row 1, column 45
Source code:
<div xmlns="http://www.w3.org/1999/xhtml"><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

Error: uncaught exception: [Exception... "An invalid or illegal string was specified"  code: "12" nsresult: "0x8053000c (NS_ERROR_DOM_SYNTAX_ERR)"  location: "http://127.0.0.1/WebLibThirdParty/JavaScript//jquery.js Line: 112"]

My jquery code is simple:

$(document).ready(function() {
        // when the #guest_details is clicked
    $('#guest_details').click(function() {

        var postedData = $('#guest-details-dialog-contents form').serialize();
        var uri = '/';
        $.ajax({
            type: 'POST',
            data: postedData,
            url: uri,
            success: function(data) {
                // this works
                            alert(data);
                            // this doesn't work
                alert($(data).html());
            }
        });

        return false;

    });
});

As you can see, the problematic line is:

alert($(data).html());

In the ajax callback. The PHP script returns valid XHTML (served as XML) so I am buffled by this issue.

EDIT:

Ok. The problem is that AJAX returns messed up XHTML. It changes tags to HTML:

<br /> becomes <br>
<input type="text" name="someInput" /> becomes <input type="text" name="someInput">
and so on


Solution 1:[1]

I really don't think the messed up XHTML is the problem. From the jquery documentation ( http://api.jquery.com/html/ ) for the html() method: This method is not available on XML documents. So if you're returning XML, that may be your problem.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 A. M.