关于提交问题的PHP Ajax Html

时间:2016-04-11 21:18:27

标签: javascript php jquery html ajax

所以我有下面的代码,这一切都有效,但成功/错误我可以搞清楚。

这是settings.php

<li><button type="button" onclick="ApimanagementFunctioncall()" id="button1" class="btn btn-default btn-lg"><a href="#">Api management</button></a></li>
<script>
    function ApimanagementFunctioncall(){
    var xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function() {
    if (xhttp.readyState == 4 && xhttp.status == 200) {
    document.getElementById("display").innerHTML = xhttp.responseText;
    }
    }
    xhttp.open("GET", "Apimanagement.php", true);
    xhttp.send();   
    }

    </script>

Apimanagement.php

MySQLI表在这里。

<div class="container">
    <div class="row text-left">
     <button type="button" class="btn btn-default btn-lg"  data-toggle="modal" data-target="#AddApi"><span class="glyphicon glyphicon-plus"></span>Add Api</button>
    </div>
</div>

<div class="modal fade" id="AddApi" role="dialog">
<?php
include ("ApiAdd.php");
?>
</div>

这是Addapi.php

<?php
    $errorMessage = "";
    $UserId = "11";

     if(isset($_POST['submit'])){
       $VarKeyID = $_POST["KeyID"];
       $VarVCode = $_POST["VerificationCode"];
       $errorMessage1 = ""; 
       $errorMessage2 = "";
       $VkeyAdd= ""; $VCodeAdd = "";
        if(empty($VarKeyID) == false){
            if(is_numeric($VarKeyID) == true){
                if(strlen($VarKeyID) !== 8){
                    echo '<script type="text/javascript">alert("Key Id is not the correct length of 8 numbers!\n");</script>';}
                    else{ $VKeyAdd = "true";}
            }else{$errorMessage1 = '<script type="text/javascript">alert("Key Id should only be numbers!");</script>';}
        }else{$errorMessage1 ='<script type="text/javascript">alert("Please Enter a Key ID!");</script>';}

        if(empty($VarVCode) == false){
            if(ctype_alnum($VarVCode) == true){
                if(strlen($VarVCode) !== 64){
                    $errorMessage2 = "Verification Code should be 64 characters!";
                    }else{$VCodeAdd = "true";}              
            }else{$errorMessage2 = '<script type="text/javascript">alert("Verification Code should only be letters and numbers!");</script>';}
        }else{$errorMessage2 ='<script type="text/javascript">alert("Please Enter a Verification Code!");</script>';}

        If($VKeyAdd == "true"){
            if($VCodeAdd == "true"){
            echo "Next";}else{echo $errorMessage2;}
        }else{echo $errorMessage1;}
     }
?>

<div  id="AddApi">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
            <a href="Settings.php" title="Close" class="close"><span class="glyphicon glyphicon-remove"></span></a>
            <h2> Add Api Key </h2> 
            <a href="https://community.eveonline.com/support/api-key/CreatePredefined?accessMask=1073741823" target="_blank" class="btn btn-link" role="button">Api create key here</a>
            <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="POST">
            Key ID</br> <input type="text" name="KeyID" maxlength="8" value=""></br>
            Verification Code</br> <input type="text" name="VerificationCode" maxlength="64" min="64" value=""></br>
            <input type="submit" name="submit" value="Submit" formtarget="_Self">
            </form>
        </div>
    </div>
<div>

现在我知道我遗漏了一些代码,但相关的代码在这里并且有效。问题是当我单击表单的输入提交按钮时。它打开了服务器上的addApi.php,而我希望它能够回显输入表单上的错误,如果成功,则转到在div中加载apimanagement.php页面的Settings.php页面。

0 个答案:

没有答案