问题
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