How can I get jQuery $('#div').html() to work in IE7+?
I have written ajax requests to change divs on the fly by using the code below:
$(document).ready(function(){
$.ajax({
type : 'GET',
url : url,
success : function(data){
$('#some_div').html(data);
}
});
});
It works great in Chrome, FF, Safari and mobile devices, but it returns nothing in IE7+. Am I doing something wrong? Or, is this an annoying IE bug? If so, how do I work around it?
EDIT Here is the HTML of the file I'm trying to pull in:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Store Notes</title>
<meta name="description" content="" />
<meta name="keywords" content="" />
<link type="text/css" href="/css/smoothness/jquery-ui-1.8.11.custom.css" rel="stylesheet" media="all" />
<link type="text/css" href="/css/colorbox.css" rel="stylesheet" />
<link type="text/css" href="/css/rep.css" rel="stylesheet" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax开发者_Python百科/libs/jquery/1.5.1/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.11/jquery-ui.min.js"></script>
<script type="text/javascript" src="/js/rep/global.js"></script>
<script type="text/javascript" src="/js/jquery.colorbox-min.js"></script>
</head>
<body><table style="width:100%;" cellspacing="12px">
<tr><td><b>Some Guy</b> <span class="small">Apr 28th</span><br />testing123</td></tr><tr><td><b>Some Guy</b> <span class="small">Apr 28th</span><br />testing123</td></tr></table>
</body>
</html>
Is the HTML you receive from the AJAX-request valid? If not this will result in IE failing, while some of the other browsers don't care.
Is 'div' the actual name of the id in your HTML? IE can be finicky when names conflict with actual tag names or if the id and the name on the HTML element are the same. Try changing 'div' to something descriptive.
It's good practice to do that anyway
try this,
document.getElementById("div").innerHTML = data
Hope helps!
I know it is to late please try this
$('#some_div').html(data.toString());
please read this article i hope this help
精彩评论