2016-06-24 6 views
-1

このコードにはリンクに関連したエラーがあり、ページが開かれていません。私が与えているリンクにエラーがあり、それが表示されません他のページのデータを持っています。私のパソコンでは、ファイルのリンクは "D:\ xampp \ htdocs \ cart \ welcome.php"というフォルダを "D:\ xampp \ htdocs \ cart"それを右にし、私はあなたがWebサーバを実行して、あなたの解像度を要求する必要がwebstieajaxを使って表示新しいウィンドウが開きます

<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>

+0

http:// D:/ xampp/htdocs/cart/welcome.php'は有効なURLではありません。 Webサーバーとファイルシステムは2つの非常に異なるものです。 – David

+0

'' http:// D:/ xampp/htdocs/cart/welcome.php ''これを' 'file:/// D:/ xampp/htdocs/cart/welcome.php' 'に変更します。 '絶対パス'または '絶対パス'を提供する必要があります。 '相対リンク 'を提供することがベストプラクティスです。 –

+0

それのためのフィドラーを作成して、別の人があなたのバグを追跡するのは簡単です。 –

答えて

2

をしていないXAMPPで私のPCでこれを使用していますネットワーク名(例: http://localhost/cart/welcome.php)。

ローカルファイルパスへのURLの代わりにhttp:file:で始まりますが、XMLHttpRequestのほとんどの実装がそれをサポートすることを拒否なり、それがPHPを実行させません(PHPいるので、この文脈では、 サーバサイドプログラミング言語)。

+0

私はそれを始めましたが、それでもエラーを表示しています –

+0

そして、エラーメッセージは...? – Quentin

+0

"要求に問題がありました。"基本的に警告としてのコード内 –

関連する問題