AJAX and setTimeout on Internet Explorer
AJAX and setTimeout on Internet Explorer
我正在尝试使用ajax获取服务器日期时间。我在Internet Explorer上运行脚本时遇到问题。
我以前的密码是这样的。(但它只显示客户端的电脑日期时间,客户端可以随时更改)
var _current = new Date();
var _day = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"][_current.getDay()];
var _month = ["January","February","March","April","May","June","July","August","September","October","November","December"][_current.getMonth()]
var _date = _current.getDate(); if(_date < 10){_date = "0" + _date;}
var _year = _current.getFullYear();
var _hours = _current.getHours(); if(_hours > 12){_hours = _hours - 12; var ampm = "PM"}else{var ampm = "AM"}if(_hours < 10){_hours = "0" + _hours;}
var _minutes = _current.getMinutes(); if(_minutes < 10){_minutes = "0" + _minutes;}
var _seconds = _current.getSeconds(); if(_seconds < 10){_seconds = "0" + _seconds;}
$("#datetime").html("");
$("#datetime").html(_day + ", " + _month + " " + _date + ", " + _year + ", " + _hours + ":" + _minutes + ":" + _seconds + " " + ampm + "");
输出:2015年12月2日星期三上午11:47(GMT+8)
所以,我切换到AJAX并制作了一个PHP页面。
function getDateTime(){
$.ajax({
url: 'datetime.php',
success:function(content){
$("#datetime").html("");
$("#datetime").append(content);
}
});
window.setTimeout(getDateTime,1000);
}
php
<?php
// Set Timezone
date_default_timezone_set('Asia/Taipei');
// Display DateTime
echo date("l, F d, Y, h:i:s A",strtotime('Now'))."(GMT".date("O",strtotime('Now')).")";
?>
输出:2015年12月2日星期三上午11:47(GMT+0800)
对我来说,这看起来像是ajax调用的缓存问题,因为请求URL一直都是相同的。你可以试试
$.ajaxSetup({
cache: false
});
这将添加一些随机请求查询字符串,并将打破任何缓存问题(如果有的话)。也许值得一试。
相关文章:
- 视频HTML没有'无法在Internet Explorer 11上工作
- Internet Explorer缺少占位符支持,特别是密码字段
- Internet Explorer中的文本换行错误
- 为什么我在Internet Explorer上看不到html元素
- internet explorer 8兼容模式下的Youtube api错误
- 当浏览器控制台未打开时,为什么要求会导致Internet Explorer 9超时
- Internet Explorer 8. Events
- jQuery表单验证适用于Mozilla和Internet Explorer,但不适用于Chrome或Safari
- element.dataset in Internet Explorer
- Facebook FB.init”;访问被拒绝”;在Internet Explorer 11中
- JavaScript不适用于internet explorer和Firefox,但适用于谷歌
- 在Internet Explorer中,向所选内容添加选项不起作用
- 在Internet Explorer中从二进制文件打开PDF
- elementproblem internet explorer
- 我可以使用哪些方法在Internet Explorer中禁用Alt+*X*
- 如何在Internet Explorer中使用javascript设置cookie
- 只有当alert()在带有AJAX的internet explorer中使用时,Javascript才会更新UI
- sharepoint站点的internet explorer中出现Javascript错误
- Internet Explorer重新加载IFrame
- 如何在不使用Internet Explorer的情况下从未挂起的HTML文件执行程序