$ {document).ready(函数不加载,除非刷新 [英] $(document).ready(function not loading unless refreshed

查看:168
本文介绍了$ {document).ready(函数不加载,除非刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jQuery和$(document).ready事件.当我在IE8中加载时,出现错误对象不支持此属性或方法".当我刷新时,它工作正常.这是我的代码:

I am using jQuery and the $(document).ready event. when i load in IE8 i get an error "Object doesn't support this property or method". When i refresh it works fine. Here is my code:

    <script language="text/javascript">
    $(document).ready(function ()
    {
        var xmlhttp;
        xmlhttp=new XMLHttpRequest();
        xmlhttp.onreadystatechange=function()
       {
     if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
       document.getElementById("loginbox").innerHTML=xmlhttp.responseText;
       }
    }
        xmlhttp.open("POST","loginform.php",true);
       xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
       xmlhttp.send();
   });
  </script>

我的头部标记中有以下内容:

I have the following in my head tag:

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

我尝试过$(window).load和其他任何帮助,我们将不胜感激.

Any help would be appreciated i have tried $(window).load and others.

推荐答案

包含jQuery库时,请使用jQuery库,因为仅使用$(document).ready()函数.

Use the jQuery library when you include it, as you are using only the $(document).ready() function.

尝试以下代码(它可以完成与您完全相同的操作):

Try this code (it accomplishes the exact same thing as yours):

$(document).ready(function() {
  $.post('loginform.php', $('#id_of_your_login_form').serialize(), function(response) {
    $('#loginbox').html(response);
  });
});


此行也可能有问题:


This line also might be problematic:

<script language="text/javascript">

您指定的是type,而不是language.尝试以下方法:

You are specifying the type, not the language. Try this one instead:

<script type="text/javascript">

这篇关于$ {document).ready(函数不加载,除非刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆