Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/471.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 向MySQL发布请求_Javascript_Mysql_Json_Post - Fatal编程技术网

Javascript 向MySQL发布请求

Javascript 向MySQL发布请求,javascript,mysql,json,post,Javascript,Mysql,Json,Post,我有下一个密码 <!doctype html> <html class=""> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Nieuwe gebruiker | Sociale buurt</title> <link href="boil

我有下一个密码

<!doctype html>

<html class="">

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Nieuwe gebruiker | Sociale buurt</title>
<link href="boilerplate.css" rel="stylesheet" type="text/css">
<link href="onzebuurt.css" rel="stylesheet" type="text/css">

<script type="text/javascript" language="javascript">

function formulierValideren() {     
        if (document.getElementById('Username').value == '' || document.getElementById('Username').value == null)
        {
            alert ('Gebruikersnaam is verplicht.');
            document.getElementById('Username').style.borderColor = "red";
            return false;
        }
        else if (document.getElementById('Wachtwoord').value == '' || document.getElementById('Wachtwoord').value == null)
        {
            alert ('Wachtwoord is verplicht.');
            document.getElementById('Wachtwoord').style.borderColor = "red";
            return false;
        }
        else if (document.getElementById('Wachtwoord2').value == '' || document.getElementById('Wachtwoord2').value == null)
        {
            alert ('Bevestig wachtwoord.');
            document.getElementById('Wachtwoord2').style.borderColor = "red";
            return false;
        }
        else if (document.getElementById('Wachtwoord2').value != document.getElementById('Wachtwoord').value)
        {
            alert ('Wachtwoorden komen niet overeen.');
            document.getElementById('Wachtwoord2').style.borderColor = "red";
            return false;
        }
        else
        {
            $("#bevestig").click(function() {
                gebruikerToevoegen();
            });

            var msg = "Registratie succesvol. Klik op OK om u aan te melden op de site.";
            if(confirm(msg)){
            setTimeout(function() {window.location.href = "http://webs.hogent.be/kevinbaeyens/"})
            }
        }
        //end if
}//end function

function gebruikerToevoegen() {
var request = new XMLHttpRequest();
request.open("POST", url);
request.onload = function() {
    if (request.status == 201){
        alert("everything OK!");
    } else {
        alert("you're wrong");
    }
};
}

</script>
</head>
<body class="body2">
<div class="gridContainer clearfix">
<div class="header1">
    <center>    
    Nieuwe gebruiker
    </center>
</div>
    <div id="formulier2">
        <form method="post" name="form" action="">
            <p class="labels"><center>Gebruikersnaam *</center></p><input id="Username" type="text" name="Username" placeholder="Gebruikersnaam" size="50">
            <p class="labels"><center>Wachtwoord *</center></p><input id="Wachtwoord" type="password" name="Wachtwoord" placeholder="Wachtwoord" size="50">
            <p class="labels"><center>Bevestig wachtwoord *</center></p><input id="Wachtwoord2" type="password" name="Bevestig wachtwoord" placeholder="Bevestig wachtwoord" size="50">
            <br />
            <a href="index.html" style="text-decoration:none"><center><img id="return" name="jsbutton" src="return.png" alt="Terug" /></center></a>
            <br />
            <center><input id="bevestig" type="image" src="Bevestig.png" width="200"  height="50" border="0" alt="SUBMIT!" onclick="formulierValideren()"></center>
            <br />
        </form>
    </div>
</div>
</body>
</html>

Nieuwe gebruiker|Sociale buurt
函数formulierValideren(){
if(document.getElementById('Username')。value=''|| document.getElementById('Username')。value==null)
{
警报(“Gebruikersnaam是verplicht”);
document.getElementById('Username').style.borderColor=“红色”;
返回false;
}
else if(document.getElementById('Wachtwoord')。值=''| | document.getElementById('Wachtwoord')。值==null)
{
警报(“Wachtwoord是verplicht”);
document.getElementById('Wachtwoord').style.borderColor=“红色”;
返回false;
}
else if(document.getElementById('Wachtwoord2')。值=''| | document.getElementById('Wachtwoord2')。值==null)
{
警报(“贝夫斯蒂格·瓦赫特伍德”);
document.getElementById('Wachtwoord2').style.borderColor=“红色”;
返回false;
}
else if(document.getElementById('Wachtwoord2').value!=document.getElementById('Wachtwoord').value)
{
警惕(“Wachtwoorden komen niet overeen”);
document.getElementById('Wachtwoord2').style.borderColor=“红色”;
返回false;
}
其他的
{
$(“#bevestig”)。单击(函数(){
gebruikerToevoegen();
});
var msg=“注册成功。请确认现场操作的正确性。”;
如果(确认(味精)){
setTimeout(函数(){window.location.href=”http://webs.hogent.be/kevinbaeyens/"})
}
}
//如果结束
}//端函数
函数gebruikerToevoegen(){
var request=new XMLHttpRequest();
打开(“POST”,url);
request.onload=函数(){
if(request.status==201){
警惕(“一切正常!”);
}否则{
警惕(“你错了”);
}
};
}
Nieuwe gebruiker

Gebruikersnaam*

瓦赫特伍德*

贝夫斯蒂格·瓦赫特伍德*




我想将来自#Username和#Wachtwoord的数据发送到我的MySQL数据库。
请帮帮我,我已经被困在这上面差不多一个星期了。如果有人能帮助我,我会很高兴的!如果我需要提供更多信息,请先问我

我以为你在寻找客户端解决方案(无论如何,这将是一个非常糟糕的主意)。杰森是对的。但是,如果您想要某种自动化的东西,可以看看smarty php。不过,首先你必须学习一些基本知识,并观看一个在本视频tuto中可以找到的非常清晰的示例:

1)你为什么要使用框架(似乎是jQuery)和这样的涂鸦

var request = new XMLHttpRequest();
你可以看看:

2) 建议使用e.preventDefault,而不是在验证时返回false。

3) 你的“行动”是什么?或者:你的url指向哪里? 如前所述:服务器端需要某种“端点”:


或者,您需要在服务器上运行一些东西(PHP、ASP.NET等),以接受post请求并将其传递给MySQL。如果没有中间层,你不能直接发布到MySQL。谢谢你的帮助,非常有用!唯一的问题是,我必须为一个项目这样做,我们不能使用PHP,所以我想我必须使用JQuery或其他方法来解决这个问题?唯一的问题是怎么做?