我遇到了 IE 问题,但找不到解释。我有这段代码可以在 Chrome 和 Firefox 中触发警报,但在 IE 中却不会。我什至不调用 GetDictBySubtitle()
。
<?php
header('Content-type: text/html; charset=UTF-8');
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>Something</title>
<link rel="stylesheet" href="../css/bootstrap.css" type="text/css">
<link href="../css/dashboard.css" rel="stylesheet"/>
<script>
function GetDictBySubtitle() {
var userid = "000000000027";
var subid = "6317450";
postData = {"userid":userid, "subtitleid":subid};
$.ajax({
url: "/cgi-bin/get_movie_dictionary.py",
type: "post",
datatype:"json",
async : true,
data: {postData},
success: function(response){
alert(response);
}
});
}
function GetAccountData() {
var userid = "000000000027";
alert(userid);
}
</script>
</head>
<body>
<script>
window.onload = function() {
GetAccountData();
}
</script>
AN ALERT SHOULD BE DISPLAYED
</body>
<script src="../js/jquery.js"></script>
<script src="../js/jquery-ui.min.js"></script>
<script src="../js/bootstrap.min.js"></script>
<script src="../js/light-bootstrap-dashboard.js"></script>
</html>
我还在请求中添加了 cache: false
,但这不是缓存问题,因为我删除了 IE 中的所有内容,重新启动它,但警报仍然潜伏在黑暗中的某个地方。
注意:在 IE 中调试页面时,我在 window.onload block 中收到 GetAccountData() is undefined
错误。
我使用的是 IE 10、Chrome 50、Firefox 45。
这太棒了,如果我有时间打发时间,我可以随时依靠 Microsoft。
最佳答案
改变
data: {postData},
至
data: postData,
然后再次测试。
为什么?
因为postData
是一个对象
。
{postData}
不正确。在这种情况下,Internet Explorer 已检测到错误并阻止执行。
关于javascript - IE 的奇怪 ajax 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37242629/