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

怎甘沉沦 提交于 2020-01-05 07:46:14

问题


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

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


回答1:


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


来源:https://stackoverflow.com/questions/6234579/document-readyfunction-not-loading-unless-refreshed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!