我有一个 ajax 问题,页面加载后 Javascript 不呈现。我有这个代码:
<script>
function loadXMLDoc() {
var xmlhttp;
if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("fb-root").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET", "like.php", true);
xmlhttp.send();
}
</script>
</head>
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function () {
FB.init({
appId: 'XX',
status: true,
cookie: true,
xfbml: true
});
FB.getLoginStatus(function (o) {
if (!o && o.status) return;
if (o.status == 'connected') {
// USER IS LOGGED IN AND HAS AUTHORIZED APP
window.onload = loadXMLDoc();
} else if (o.status == 'not_authorized') {
window.onload = loadXMLDoc();
} else {
// USER NOT CURRENTLY LOGGED IN TO FACEBOOK
document.write("connect3")
}
});
};
(function () {
var e = document.createElement('script');
e.async = true;
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
</script>
like.php 文件包含
<?php echo <script src='/facebook/src/like.js'></script>; ?>
当用户登录 facebook 时,ajax 加载但脚本不执行。正文部分的脚本经过检查并且运行良好。问题出在哪里?
谢谢!