簡體   English   中英

錯誤:未捕獲的異常:[異常...“指定了無效或非法的字符串”

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

我在 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

我真的不認為混亂的 XHTML 是問題所在。 來自 html() 方法的 jquery 文檔 ( http://api.jquery.com/html/ ):此方法不適用於 XML 文檔。 因此,如果您要返回 XML,那可能是您的問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM