错误:未捕获的异常:[例外...“指定了无效或非法字符串”

时间:2010-09-29 10:26:33

标签: javascript jquery

我在Firefox错误控制台中遇到的这两个错误:

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"]

我的jquery代码很简单:

$(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;

    });
});

正如您所看到的,有问题的一行是:

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

在ajax回调中。 PHP脚本返回有效的XHTML(作为XML),因此我对此问题进行了缓冲。

编辑:

确定。问题是AJAX返回搞砸XHTML。它将标签更改为HTML:

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

1 个答案:

答案 0 :(得分:0)

我真的不认为混乱的XHTML是问题所在。来自jquery文档(http://api.jquery.com/html/)的html()方法:此方法在XML文档中不可用。因此,如果您要返回XML,那可能是您的问题。

相关问题