Dhruv Tyagi Dhruv Tyagi - 9 months ago 27
Ajax Question

want to change the state through AJAX

Actually as the button press, I want to call the function and through this I want to update some Data on db.

Here is my Code :

echo "<button type='button' class='btn btn-info btn-md' id='click' onclick='loadDoc()'>Approve</button>";
// as the button is click loadDoc() is call

code is here :

function loadDoc()
var xhttp = new XMLHttpRequest();
xhttp.open('GET', 'updatebox.php', true);
document.getElementById('demo').innerHTML = 'hello';

Here is my

$query="UPDATE orders
SET status='cooking'
WHERE order_id='this.order_id'";

// here is the problem i just want to update some data into my table and after that i want to remove the button



To update the data in your table you have to use update query, take a look to SQL Update. to check if the db is updated use condition like example below :

if (mysqli_query($connection,$query)) {
    echo "Record updated successfully";
} else {
    echo "Error updating record: " . mysqli_error($conn);

Then to hide the button you could use get() request instead :


OR with XMLHttpRequest success callback :

xhttp.onreadystatechange = function() {
    if (xhttp.readyState == 4 && xhttp.status == 200) {
        document.getElementById("click").style.display = 'none';

Hope this helps.