代码之家  ›  专栏  ›  技术社区  ›  Greg B

使用ASP.NET UpdatePanel时出现JavaScript错误

  •  1
  • Greg B  · 技术社区  · 14 年前

    我用的是 UpdatePanel 交换 ActiveView 一个 MultiView .

    在IE6、7、8和Chrome7中,当UpdatePanel返回时,我得到一个JavaScript错误。在Firefox3.6.1中没有错误报告(在错误控制台或Firebug中)。

    错误位于ScriptResource.axd的第3621行

    function Sys$_ScriptLoader$_loadScriptsInternal() {
        var session = this._currentSession;
        if (session.scriptsToLoad && session.scriptsToLoad.length > 0) {
            var nextScript = Array.dequeue(session.scriptsToLoad);
            var scriptElement = this._createScriptElement(nextScript);
    
            if (scriptElement.text && Sys.Browser.agent === Sys.Browser.Safari) {
                scriptElement.innerHTML = scriptElement.text;
                delete scriptElement.text;
            }            
            if (typeof(nextScript.src) === "string") {
                this._currentTask = new Sys._ScriptLoaderTask(scriptElement, this._scriptLoadedDelegate);
                this._currentTask.execute();
            }
            else {
                var headElements = document.getElementsByTagName('head');
                if (headElements.length === 0) {
                     throw new Error.invalidOperation(Sys.Res.scriptLoadFailedNoHead);
                }
                else {
    line 3621:        headElements[0].appendChild(scriptElement);
                }
    
    
                Sys._ScriptLoader._clearScript(scriptElement);
                this._loadScriptsInternal();
            }
        }
        else {
            this._stopSession();
            var callback = session.allScriptsLoadedCallback;
            if(callback) {
                callback(this);
            }
            this._nextSession();
        }
    }
    

    Uncaught SyntaxError: Unexpected number

    Chrome的开发工具显示 headElements 是一个 NodeList 只有一个元素 scriptElement 是一个 HTMLScriptElement NodeList and ScriptElement

    这个错误的原因可能是什么?为什么它只出现在IE和Chrome上,而不是Firefox上?

    2 回复  |  直到 14 年前
        1
  •  4
  •   Greg B    12 年前

    我在 ScriptManager.RegisterStartupScript . 当浏览器在 <script> tag被添加到DOM中,正如@Rahul在评论中所建议的那样。

        2
  •  0
  •   Jorge.Methew    7 年前

    gzip压缩也可能会导致寻找解决方案的人遇到这种问题。