Error: uncaught exception: [Exception ... "Invalid or illegal string specified"

These 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 problem line is:

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

In the ajax callback. The PHP script returns a valid XHTML (used as XML), so I discarded this problem.

EDIT:

Ok The problem is that AJAX returns corrupted XHTML. It changes the tags to HTML:

<br /> becomes <br>
<input type="text" name="someInput" /> becomes <input type="text" name="someInput">
and so on
+3
source share
1 answer

, XHTML - . jquery (http://api.jquery.com/html/) html(): XML. , XML, .

0

Source: https://habr.com/ru/post/1767145/


All Articles