美好的一天。我試圖使用JavaScript將登錄數據(電子郵件,密碼,IP地址,日期)發佈到文件(all.txt)。這很難。請,你能幫忙嗎?用JavaScript發佈登錄數據
<head><script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script type="text/javascript">
function validatePass(){
var password = document.getElementById('password').value;
if (password == "cm"){
alert('Yeah, you are in!')}
else{
alert('Give it another shot')}
}
$('#enter').on('submit', function(e){
e.preventDefault();
$.ajax({
type: "POST",
url: "/all.txt",
data: $(this).serialize(),
success: function() {
alert('success');
}
});
});
</script> </head>
<form id="enter" action="http://google.com" onsubmit="return (this.password.value==='cm')?true:false;">
<link href="https://fonts.googleapis.com/css?family=Raleway" rel="stylesheet">
<input type="text" id="email" name="email" style="width: 225px; border: 0px solid #CDCDCD; color: rgba(0, 0, 0, 0.5); font-family: 'Raleway', sans-serif; font-weight: normal; font-size: 1em; background-color: #FFFFFF; text-align: center;" onblur="if (this.value == '') {this.value = 'email';}" onfocus="if(this.value == 'email') {this.value = '';}" value="email">
<p>
<input type="password" id="password" name="password" style="width: 225px; border: 0px solid #CDCDCD; color: rgba(0, 0, 0, 0.5); font-family: 'Raleway', sans-serif; font-weight: normal; font-size: 1em; background-color: #FFFFFF; text-align: center;" onblur="if (this.value == '') {this.value = 'password';}" onfocus="if(this.value == 'password') {this.value = '';}" value="password">
<p>
<input type="submit" value="log" name="log" onclick="validatePass();" style="margin: 40px 40px 40px 90px; color: #ca0000; border: 0px; background-color: rgba(51, 51, 51, 0); font-family: 'Raleway', sans-serif; font-weight: normal; font-size: 1em;" >
</form>
「這很難」不是一個有用的問題。你有什麼問題? – Barmar
你不應該在Javascript中檢查密碼,這應該在服務器上完成。 – Barmar
您無法發佈到文本文件。 'POST'需要將數據提交給服務器上運行的腳本。腳本可以寫入文件。 – Barmar