【问题标题】:Import JQuery-Library causes continious refresh webpage导入 JQuery-Library 导致网页持续刷新
【发布时间】:2014-01-29 12:22:46
【问题描述】:

我遇到了一个我无法解释的问题

考虑 html 页面的以下头部

<head runat="server">
<title></title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<style type="text/css">
</style>

<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script type="text/javascript" language="javascript">
    function ControleInput() {

        document.getElementById('Ophalen_button').disabled = true;
        document.getElementById('Wegschrijven_button').disabled = true;
        var allFields = true;

        //Controleren op de aanwezigheid van een FS-Nummer
        if (document.getElementById('FSNummer').value.length > 0) {
            document.getElementById('Ophalen_button').disabled = false;
        }
        else
        {allFields = false; }

        //Controleren op de aanwezigheid van een alias
        if (!document.getElementById('AliasPartner').value.length > 0)
        { allFields = false; }
        //Controleren op de aanwezigheid van een BTW-Nummer
        if (!document.getElementById('BtwNummerLeverancier').value.length > 0)
        { allFields = false; }
        //Controleren op de aanwezigheid van een afkorting
        if (!document.getElementById('Afkorting').value.length > 0)
        { allFields = false; }

        if (allFields) {
            document.getElementById('<%=Wegschrijven_button.ClientID %>').disabled = false;
        }
    }

    function ConfirmIgnoreBTWNbr() {
        if (confirm("Dit BTW-Nummer is reeds in gebruik. Deze zal bij het wegschrijven van gegevens worden overgeslagen. Is dit in orde?")) 
        {
            $.ajax({
                type: "GET",
                url: "SalesSetupHIC.aspx?action=sendData"
            })
        }
    }
</script>

page_behind 上的代码(加载事件)

    Fouttekst.Text = String.Empty
    //enable disable some buttons and do some layoutactions

    Dim WindowsUser As String = Request.ServerVariables("LOGON_USER")
    t.Toegelaten(WindowsUser)
    If Not Page.IsPostBack Then

         //Perform some layoutactions

    End If

    //Get Some Data
    If (ListBoxBtwNummers.Items.Count = 0) Then
        ListBoxBtwNummers.DataSource = _myProxy.GetBTWNummersInGebruik(WindowsUser)
        ListBoxBtwNummers.DataBind()
    End If

    //Add some handlers
    FSNummer.Attributes.Add("onkeydown", "ControleInput()")
    AliasPartner.Attributes.Add("onkeydown", "ControleInput()")
    BtwNummerLeverancier.Attributes.Add("onkeydown", "ControleInput()")
    Afkorting.Attributes.Add("onkeydown", "ControleInput()")

    //If Querystring is present do something
    If (Request.QueryString.Count > 0) Then
        WegschrijvenData()
    End If

现在这个页面在我访问它时会不断刷新页面:

 http://**MyPcName**/VirtualDirectory>/Default.aspx.
 http://**MyIP-Adres**/VirtualDirectory>/Default.aspx

但当我访问该页面时不会

 http://**localhost**/VirtualDirectory>/Default.aspx
 http://**127.0.0.1**/VirtualDirectory>/Default.aspx

问题出在

 <script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript">

删除库可解决刷新问题。但阻止我使用 ajax 函数。我尝试了很多方法来包含该库,但到目前为止都没有运气。

所以我对这个事件的问题是

1) 为什么会不断刷新?

2) 我该如何解决?(仍然使用 JQuery ofc)

3) 在这种情况下使用什么调试器(Firebug/IE-Console)没有帮助

也欢迎任何新的想法。

谢谢

更新:引用另一个 jquery 库(本地和互联网上)也没有解决问题。其他应用程序继续使用相同的库而不会出现问题。

更新:使用 Firebug/IE-Console 进行调试没有产生任何解决方案。我还是卡住了。

【问题讨论】:

  • 您是否尝试过从其他地方(例如 Google 托管库)加载 JQuery 以查看您正在访问的库是否存在问题?
  • 您可以尝试在本地应用程序中复制您的 JQuery 并提供参考吗?
  • 尝试了两种解决方案都没有运气。 Google Hosted Library 是我的原始来源。这就是为什么我希望在更改为 Code.query.com 时它会得到解决。维护 Jquery 的本地副本仍然会产生相同的血腥结果:-| .我想 Jquery 只是不再喜欢我了

标签: javascript asp.net jquery refresh


【解决方案1】:

经过一番痛苦的搜索,我们终于找到了问题的根源。该问题与Jquery 或使用的方法无关。

最初的开发人员使用 VS2008 创建了解决方案。然而,他并没有“清理”他的 html。由于依赖VS 2008,html中appread如下代码

<body id="PageBody" runat="server" bgcolor="#b0c4de" ms_positioning="GridLayout"
onresize="document.location=window.location;">

显然错误就在这里:onresize="document.location=window.location;" 去掉这行dit解决了网页的不断闪烁。很可能 Jquery 在调整页面大小时触发了某个地方。

这件事的结束:

  1. 永远不要依赖从 VS 生成的 HTML(我知道)
  2. 永远不要依赖前辈编写的 HTML

感谢所有努力解决我的问题的人!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-30
    相关资源
    最近更新 更多