Why doesn't this jQuery code work in IE? [duplicate]
This works in all browsers except IE. I have no idea why. Its just an ajax clock that ticks through the seconds.
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Time Program Test</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready( function(){
zone = 'Africa/Djibouti';
ajaxTimeCall(zone, ajaxCallback);
});
function ajaxTimeCall(zone, callback) {
$.ajax({
type: 'get',
url: 'time.php',
context: this,
data: 'location=' + zone,
success: function (data){
var dataSplit = data.split(".");
var isDST = dataSplit[1];
var newTime = new Date(dataSplit[0]);
//console.log(newTime);
if(isNaN(newTime))
{
$('#clock_input').val("Timezone Not Recognized");
return;
}
$('#clock_input').val(newTime);
callback(isDST);
}
});
}
function ajaxCallback(isDST) {
setTimeout("ajaxTimeCall(zone, ajaxCallback)", 1000);
if (isDST ==开发者_如何学运维 1)
$('.DST').removeClass('noshow');
}
</script>
<style type="text/css">
.noshow { display: none;}
.DST {color: red; font-size: 14px;}
</style>
</head>
<body>
<h1> World Time Ajax Testing</h1>
<span class="DST noshow">(DST)</span>
<form name="test" action="">
<input id="clock_input" style="width: 175px; font-size: 14px;" type="text" value="Turn on Javascript" />
</form>
</body>
</html>
I know you've already solved this with a POST
, but there is another way as well, use the cache
option for $.ajax()
. By setting it to false
, jquery will append a timestamp to the URL as a parameter, forcing a new request even in IE, you use it like this:
$.ajax({
cache: false,
//current options you already have...
});
Shouldn't your code be:
ajaxCallback(isDST);
in your ajax success callback in the function ajaxTimeCall
?
If you could provide more details about the error that you're seeing, that would also help.
精彩评论