在此代码中有一些与链接相关的错误,它不打开页面。错误可能在我给的链接,它不显示警报在我的电脑中,文件的链接是“D:\ xampp \ htdocs \ cart \ welcome.php”,意思是它在文件夹“D:\ xampp \ htdocs \ cart”中,现在我改变了作出正确的,我用这个在我的电脑用XAMPP不做webstie使用ajax显示打开新窗口
<html>
<head>
<script>
function check(form) {
if (form.email.value == "[email protected]") {
document.getElementById("displayu").innerHTML ="correct username".fontcolor("green");
} else if (form.email.value == "") {
document.getElementById("displayu").innerHTML ="<font color='red'>blank username</font>";
} else if (form.email.value != "") {
var email = document.getElementById('email');
var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (!filter.test(email.value)) {
document.getElementById("displayu").innerHTML ="Please provide a valid email address";
}
else {document.getElementById("displayu").innerHTML ="wrong email";}
}
if (form.pswrd.value == "123") {
document.getElementById("displayp").innerHTML ="correct password";
} else if (form.pswrd.value == "") {
document.getElementById("displayp").innerHTML ="<span style='color:red'>blank password</span>";
}
else {document.getElementById("displayp").innerHTML ="wrong password";}
makeRequest('http://D:/xampp/htdocs/cart/welcome.php');
}
function makeRequest(url) {
httpRequest = new XMLHttpRequest();
if (!httpRequest) {
alert('Giving up :(Cannot create an XMLHTTP instance');
return false;
}
httpRequest.onreadystatechange = alertContents;
httpRequest.open('GET', url);
httpRequest.send();
}
function alertContents() {
if (httpRequest.readyState === XMLHttpRequest.DONE) {
if (httpRequest.status === 200) {
alert(httpRequest.responseText);
\t \t document.open();
document.write(httpRequest.responseText);
document.close();
} else {
alert('There was a problem with the request.');
}
}
}
</script>
</head>
<body>
<h1>for login</h1>
<h3>[email protected] and password=123</h3>
<form name="login">
<div id="displayu"></div>
<div id="displayp"></div>
Username <input type="text" name="email" id="email" />
Password <input type="password" name="pswrd"/>
<input type="button" onclick="check(this.form)" value="Login" />
<input type="reset" value="reset"/>
</form>
</body>
</html>
'http:// D:/ xampp/htdocs/cart/welcome.php'不是有效的URL。 Web服务器和文件系统是两个完全不同的东西。 – David
''http:// D:/ xampp/htdocs/cart/welcome.php''把它改成''file:/// D:/ xampp/htdocs/cart/welcome.php'' ..但是为什么你需要提供“完整路径”或“绝对路径”,最好提供“相对链接”。 –
为它创建一个提琴手,因此其他人很容易追踪你的bug。 –