Note that there are some explanatory texts on larger screens.

plurals
  1. POxmlhttprequest: "password" from txt-file
    text
    copied!<p>I'm new to javascript/ajax and a bit stuck right now. The assignment is to use only javascript/ajax.</p> <p>I'm supposed to make a login-form, and when typing in the right password it will display a "secret message". Currently this message is an alert-box.</p> <p>This is in the script for validating the form input:</p> <pre><code>var riktigPassord = 'password'; var passord = window.document.passordSkjema.passord.value; if (passord == riktigPassord ) { alert("Dette er en hemmelig beskjed"); window.document.passordSkjema.passord.focus(); return true; } else { alert("Innlogging mislyktes. Passord er feil!"); window.document.passordSkjema.passord.focus(); return false; } }//slutt på funksjonen her </code></pre> <p>And this is the code for the form:</p> <pre><code>&lt;form name="passordSkjema" action="#" method="post" onSubmit="return validerPassord();"&gt; Passord: &lt;input type="text" name="passord"&gt;&lt;br&gt; &lt;input type="submit" name="knapp"&gt; &lt;/form&gt; </code></pre> <p>I'm supposed to get the password from a txt-file. (still using only javascript) and in my case, the txt-filename is "password.txt".</p> <p>I've never done this before, but I think I know how to make a XHR-object... xD</p> <pre><code>// New XMLHttpRequest-object function newXHRobjekt() { try { XHRobjekt = new XMLHttpRequest(); // Firefox, Opera, ... } catch(err1) { try { XHRobjekt = new ActiveXObject("Microsoft.XMLHTTP"); // Noen IE } catch(err2) { try { XHRobjekt = new ActiveXObject("Msxml2.XMLHTTP"); // Noen IE } catch(err3) { XHRobjekt = false; } } } return XHRobjekt; } </code></pre> <p>So.. My question is. How do I use a XHR-object to get use the functions above to check the password-input against password.txt. the file only contains the password (for instance only "12345"). and also I would like to know how to get the "secret message" from another txt-file.</p> <p>I'm aware that this isn't secure at all, but it's a part of understanding javascript/Ajax, in my classes.</p> <p>Thanks!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload