1

我有这两个按钮,用户可以单击以批准/拒绝站点上的某人,并且代码在 IE 中运行良好,但是当我尝试使用 firefox 时,单击按钮时什么也没有发生。

javascipt/ajax 代码是:

        function ApproveOrDenyStudent(i, action){
            if (window.XMLHttpRequest){
                // code for IE7+, Firefox, Chrome, Opera, Safari                
                xmlhttp=new XMLHttpRequest();
            }
            else{
                // code for IE6, IE5
                xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
            }                                                

            var newStudentEmail = "newStudentEmail" + i;

            var emailField = document.getElementById(newStudentEmail);
            var email = emailField ? emailField.value : '';       



            // Approve/deny the user
            if (action == 0){      
                xmlhttp.open("GET","ApproveStudent.php?email="+email,true); 
            }
            else if (action == 1){
                xmlhttp.open("GET","DenyStudent.php?email="+email,true); 
            }
            xmlhttp.send();
            window.location.reload();
        }

任何帮助都会很棒!谢谢!

4

1 回答 1

2

你有一个比赛条件!

xmlhttp.send();
window.location.reload();

您正在进行异步调用。您正在发出 Ajax 请求并立即替换页面!对服务器的调用没有发出。

请求完成后重新加载页面。

xmlhttp.onreadystatechange = function() {
    if(xmlhttp.readyState == 4){
        window.location.reload(true);
    }
};
xmlhttp.send();
于 2012-12-12T04:30:33.283 回答