开发者

$(document).ready(function not loading unless refreshed

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-ww开发者_高级运维w-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">

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


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

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

<script type="text/javascript">
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜