PHP:Ajax在MySQL表中复制数据

问题描述

Helllo, 我正在尝试使用Ajax和PHP将表单数据发送到MySQL表。当表单字段为空并发送数据时,我确保显示一条错误消息。多次出现此错误,给我的印象是,一旦正确重新签名了所有字段,就代表表中的条目数。突然,当我查看表格时,发现表格中的数据已重复。我无法理解这。我的AJAX代码是否将数据保留在内存中,然后在正确填写数据后将其发送回php?下面,我介绍我的AJAX代码,该代码允许我发送表单数据。

function send(){
    $("#form").on('submit',(function(e) {
     e.preventDefault();
     $("#loader").toggle();
    document.getElementById("go").disabled = true;
    var form_data = new FormData();                  
    //alert(form_data);
    $.ajax({
        type: 'POST',url: 'send_to.php',// point to server-side PHP script 
        dataType: 'text',// what to expect back from the PHP script,if anything
        cache: false,contentType: false,processData: false,//async: false,data: new FormData(this),success: function(data,status){
            if(data == 'success'){
                $("#resultat").html('<strong style="color:green;">Thank you Your transaction has been sent</strong>');
                $("input[type=text]").val(""); // Vider le formulaire
                $("input[type=number]").val(""); // Vider le formulaire
                document.getElementById('loader').style.display = "none";
                document.getElementById("go").disabled = false;
                //location.reload();
                //window.location.replace("./?home&yes");
            }else{
                $("#resultat").html('<strong style="color:red;">'+data+'</strong>');
                document.getElementById("go").disabled = false;
                document.getElementById('loader').style.display = "none";
            }
        }
     });
 }));
}

我的PHP代码:

$sql = $mysqli->prepare("INSERT INTO test (user,phone,email) VALUES (?,?,?)");
    $sql->bind_param('sis',$user,$phone,$email);
    if(!$sql->execute()){
        echo ('cant create);
    }else{
    echo 'data created';
  }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...