D
D
del9937882016-11-25 21:51:00
PHP
del993788, 2016-11-25 21:51:00

How to send and receive response from php via ajax?

Hello. There is this form: https://jsfiddle.net/n3xz195L/ . The data in the table that you see is written like this

$query = "SELECT * FROM main ORDER BY id DESC";
$result = mysqli_query($link, $query);

if (!$result) {
    die(mysqli_error($link));
}
$n = mysqli_num_rows($result);
$articles = array();
for ($i=0; $i < $n; $i++) {
    $row = mysqli_fetch_assoc($result);
    $articles[] = $row;
}
return $articles;

And in html the table looks like this:
<?php foreach($articles as $a): ?>
    <tr>
        <td class="formid"><?=$a['id']?></td>
        <td><?=$a['namenomer']?></td>
        <td><?=$a['datestart']?></td>
        <td><?=$a['dateend']?></td>
        <td><?=$a['nameclient']?></td>
        <td><?=$a['phoneclient']?></td>
    </tr>
<?php endforeach ?>

And here it all works great. php accesses the database, gets the data and displays it in html.
Now back to the form https://jsfiddle.net/n3xz195L/ . If you click on a table row, then a popup window will open, where the details of this row should be indicated. Now a question. How to ajax send the value of the id of the row we clicked on, so that php then makes a selection by this id, and then displays the data in the popup? And how do I specify the variables?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2016-11-25
@del993788

Good evening.
Here's help for you:
one
two

R
Rou1997, 2016-11-25
@Rou1997

You can do it according to this article, it is there that the simplest page without AJAX is first created along with the database, then AJAX is implemented on XHR, then it is converted to jQuery.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question