谁能帮我理解为什么这个警报不会出现?在函数newuser()
中应该显示一个警报,带有一些文本,但是当我调用它时没有任何反应。我怎样才能解决这个问题?
var xmlHttp = createXmlHttpRequestObject();
function createXmlHttpRequestObject() {
var xmlHttp;
if (window.ActiveXObject) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
xmlHttp = false;
}
} else {
try {
xmlHttp = new XMLHttpRequest();
} catch (e) {
xmlHttp = false;
}
}
if (!xmlHttp) {
alert("cant create that object hos");
}
function newuser() {
if (xmlHttp.readyState === 0 || xmlHttp.readyState === 4) {
name = encodeURIComponent(document.getElementById("name").value);
company = encodeURIComponent(document.getElementById("company").value);
nationalities = encodeURIComponent(document.getElementById("nationality").value);
phonenumber = encodeURIComponent(document.getElementById("phonenumber").value);
alert(name, company, nationalities, phonenumber);
} else {
setTimeout('newuser()', 1000);
}
}
}