A
A
Alexander2015-10-18 01:31:51
PHP
Alexander, 2015-10-18 01:31:51

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)

I don’t know how to make the requests different (well, that they would send different status 's, depending on the value)
Simply put, I want to make a button that will change the status and at the same time change itself, and execute requests.
I want to make sure that the page is not updated at the same time (well, or at least the data does not fit into the url)
How can I implement this?
It is necessary approximately it: How to make execution of request on pushing the button?
With all of the above.
And just from this example for some reason it did not work out.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nikita Shultais, 2015-10-18
@shultais

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>

now the jQuery code itself
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;
})

The AJAX request will be sent to /admin.php?id=755 because url: button.attr("href") takes its value from your button's href attribute.
The request will be sent using the POST method and expect a JSON response.
3. Now you need to write a PHP script that will process the request: enter data into the database, and return status-text in JSON with the text of the new status.

V
Vyacheslav, 2015-10-19
@nskarl

<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>

ajax.php:
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 question

Ask a Question

731 491 924 answers to any question