开发者

Updating the database with Ajax is not working [closed]

Closed. This question needs debugging details. It is not currently accepting answers.

Edit the question to include开发者_如何学运维 desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.

Closed 8 hours ago.

Improve this question

In this project, there is one user input and results for that input will be taken form database. For each of the result, there will be disable button if zone_enable is 0. If zone_enable is 1 it will show as enable. Previously, I made with <a href> to run the script and if I click on the disable or enable button, the whole page got refresh but the it updates the database. I did some research and not to reload the page, I can try on with AJAX so I tested out. But I've never tryout Ajax and if I click on disable or enable, database is no more updating.

Below codes are from Javascript. `

function Submit(){

  var productlotid = document.translot.productlotid.value;
    if (productlotid == null || productlotid ==""){
        alert("Lot ID should not be blank.");
        return false;
    }
    
 document.getElementById("result").innerHTML = SynReqData(reqHttp2,'correlationwafer_result.php?productlotid=' + productlotid );
 console.log(productlotid);
 //alert ('Request Successful.');
      //window.location.reload();
      //return false;

}

Below codes are from index page.

<body onload="OnLoad()">

<div class="container">
    

    <form class="form-horizontal" name="translot" method="post" >
    
    <form id="form" method="post">
    <div class="col" style="width: 580px; font-weight: bold; border: 1px solid SteelBlue; color: #6699CC; margin-left: 170px;">
        <p style="background-color: #6699CC; font-size: 16px; width: 580px; padding: 5px; color: #FFF; font-weight: bold; margin-left: -1px;margin-top: -1px;"></p>

    <div class="form-group">
    
  

      <br>
      <label class="control-label col-sm-4" for="productlotid">Lot ID:</label>
      <div class="col-sm-4">
        <p class="form-control-static" style="margin-top: -6px;">
            <input type="text" class="form-control" id="productlotid" name="productlotid" onkeydown="return KeyDown()" onkeyup="this.value=this.value.toUpperCase()" onkeypress="return searchKeyPress(event)" min="1" placeholder="Enter Lot ID" value="<?php echo $productlotid; ?>">
        </p>
        
      </div>
      <div id="result" style="display: inline-table; margin-left: 150px; margin-top: 22px;">
      <?php
                    include("correlationwafer_result.php");
        ?></div>
      <!--div id="result" ></div-->
      <div class="col-sm-10">
       </div>
      <br>


    </div>
    </div>
    <br>

<!-- Add/Reset -->
     
     <div style="margin-right: 65px;">
    <p align="center"><button type="button" class="btn btn-info " name="cmdSubmit" id="cmdSubmit" onclick="Submit()"><b>Go</b></button></p>
    </div>
    
    
    </form>
    
    </form>
</div>
</body>

Below codes are from correlationwafer_result.php page.

<?php 

// ini_set("memory_limit","512M");
include("_dbconn.php");
include("//sgewsnant21.amk.st.com/ewsweb/wwwroot/library/common7/db_config.inc");
include("//sgewsnant21.amk.st.com/ewsweb/wwwroot/library/common7/standard_defines.inc");
session_start();


$productlotid = isset ($_GET['productlotid'])? $_GET['productlotid']:'';

//$sql1 = "Update * FROM productdb.tbl_correlationwafer WHERE lotid = '$productlotid' ORDER BY lotid and zone_enable='0'";
$sql = "SELECT * FROM productdb.tbl_correlationwafer WHERE lotid = '$productlotid' ORDER BY product asc, zone asc";
    $result1 = mysqli_query($conn,$sql);

echo "<table id='corwafer'>";
$arr = array();

while ($row = mysqli_fetch_assoc($result1)) {

$field1name = $row["lotid"];
$field2name = $row["product"];
$field3name = $row["ewsflow"];
$field4name = $row["zone"];
$field5name = $row["zone_enable"];
$key = $field1name + ":" + $field2name + ":" + $field3name;

if (!in_array($key, $arr)){
    array_push($arr, $key);
}
?>
<form method='post' enctype='multipart/form-data' onsubmit="return false">
<?php    
   echo "<tr>";
    echo "<td>";
    if($field5name == 1){
        echo "<input type='hidden' id='chkzone' name='chkzone' value='$field4name'>";
        echo "<input type='hidden' id='pid' name='pid' value='$field1name'>";
        echo" <label for='chkzone'> Product - $field2name </label>";
        echo" <label for='chkzone'> :: Zone - $field4name </label>";
        //echo" <label for='chkzone'> :: Zone - $field4name </label>";

        //echo "<a class='btn btn-secondary text-light btn-sm' target=\"_blank\" href='test.php?id=$field4name&pid=$field1name'>Disable</a>";

        echo "<button type=\"button\" onclick=\"updateDatabase()\" style=\"margin-left:10px;\"> Disable</button>";
    } 
    else if($field5name == 0){
        echo "<input type='hidden' id='chkzone' name='chkzone' value='$field4name'>";
        echo "<input type='hidden' id='pid' name='pid' value='$field1name'>";
        echo" <label for='chkzone'> Product - $field2name </label>";
        echo" <label for='chkzone'> :: Zone - $field4name </label>";

        //echo "<a class='btn btn-secondary text-light btn-sm' target=\"_blank\" href='test_1.php?id=$field4name&pid=$field1name'>Enable</a>";
    
        echo "<button type=\"button\" onclick=\"updateDatabasee()\" style=\"margin-left:10px;\"> Enable</button>";
    }
    echo "</td>";
    echo "</tr>";
    ?>
    </form>
<?php
}

echo "</table>";

flush();
mysqli_close($conn);
?>
<script type="text/JavaScript">
function updateDatabase(){
    $.ajax({
        url: 'test.php?id=$field4name&pid=$field1name', // URL of the script to process the update
        type: 'POST', // POST request
        data: {
            // Data to be sent to the server
        },
        success: function (data) {
            // Process the response from the server
        }
    });
}

function updateDatabasee(){
    $.ajax({
        url: 'test_1.php?id=$field4name&pid=$field1name', // URL of the script to process the update
        type: 'POST', // POST request
        data: {
            // Data to be sent to the server
        },
        success: function (data) {
            // Process the response from the server
        }
    });
}
</script>

Below codes are from test.php page.

<?php 

// ini_set("memory_limit","512M");
include("_dbconn.php");
include("//sgewsnant21.amk.st.com/ewsweb/wwwroot/library/common7/db_config.inc");
include("//sgewsnant21.amk.st.com/ewsweb/wwwroot/library/common7/standard_defines.inc");
session_start();

        $zone = $_GET['id'];
        $pid = $_GET['pid'];
        $updateQuerry = "UPDATE productdb.tbl_correlationwafer SET zone_enable='0' WHERE zone='$zone' AND lotid='$pid'";
        $result = mysqli_query($conn,$updateQuerry);
         if($result){
             echo "<script>window.history.go(-1);</script>";
             //echo "<script>return false;</script>";
         }else{
             echo "<script>window.history.go(-1);</script>";
             //echo "<script>return false;</script>";
         }

flush();
mysqli_close($conn);
?>

Below codes are from tes_1.php page.

<?php 

// ini_set("memory_limit","512M");
include("_dbconn.php");
include("//sgewsnant21.amk.st.com/ewsweb/wwwroot/library/common7/db_config.inc");
include("//sgewsnant21.amk.st.com/ewsweb/wwwroot/library/common7/standard_defines.inc");
session_start();

        $zone = $_GET['id'];
        $pid = $_GET['pid'];
        $updateQuerry = "UPDATE productdb.tbl_correlationwafer SET zone_enable='0' WHERE zone='$zone' AND lotid='$pid'";
        $result = mysqli_query($conn,$updateQuerry);
         if($result){
             echo "<script>window.history.go(-1);</script>";
             //echo "<script>return false;</script>";
         }else{
             echo "<script>window.history.go(-1);</script>";
             //echo "<script>return false;</script>";
         }

flush();
mysqli_close($conn);
?>

`

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜