Answer the question
In order to leave comments, you need to log in
How to make an order status?
We need a button that will make a request to the database, and depending on the value in the database, it will change, and make another request.
well, for example:
Initially, the status value in the database = 1
In the table where the rows are displayed, there will be a button that will change the status value for this particular row (well, or this id):
<a class='btn btn-xs' name=\"status\" href=\"admin.php?id=".$row["id"]"\"> {текст} </a>
if status=1, then text=pending
if status=2, then text=in progress
if status=3, then text=done (the button should no longer be clickable)
Answer the question
In order to leave comments, you need to log in
1. Here you have generated a button using PHP and now you see it in the browser.
2. Now you need to hang an event on this button using JQuery. To do this, first add an id field to it to make it easier to access
<a class='btn btn-xs' id='status-button' name="status" href="admin.php?id=755">
в ожидании</a>
var button = $("#status-button");
button.on("click", function () {
// Отправляем AJAX запрос на сервер
$.ajax({
url: button.attr("href"),
type: "POST",
dataType: "json",
success: function (response) {
button.html(response["status-text"]);
}
});
return false;
})
<a class='btn btn-xs' onclick="changestatus(755, this)">в ожидании</a>
<script>
function changestatus(id, elem){
$.post(
'/ajax/admin/,
{id: id},
function(data){
if(data){
console.log(data.response) //Здесь обработка ответа от сервера через JS или JS+JQUERY
}
},
'JSON'
);
}
</script>
public function admin()
{
$id = $_POST('id');
$data['response']//Здесь обработка ID через MySQL и\или PHP
echo json_encode($data);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question