There are two files
index.php , server.php
In the index.php file
There is a list
<select size="3" name="abonents" id="abonents"> <option value="2938">2938</option> <option value="3781">3781</option> <option value="3591">3591</option> </select> Block
<div id="block"></div> Ajax request
<script> $(document).ready(function(){ $("#abonents").click(function(){ var a = $("#abonents").val(); $.post('server.php', {id:a}, function(data){ $("#block").text(data); }); }); }); </script> When you click on the list, the value is transferred by the POST method to the server.php file and the data from the Ajax request is supplied to the block
File server.php
<?php if (isset($_POST['id'])){ // ... // Запрос к БД, возвращет массив $result // ... echo print_r($result); } ?> Currently, the data is displayed as text
How can I transfer the Ajax request data ( Data value) to a PHP array for further processing in the index.php file?
index.phpitself, itindex.phpnot work. You can return the values in thejavascriptfunction that sent theajaxrequest. - Pyramidheadindex.php? - Xfirabajaxrequest,index.phphas already completed. Actually, the result of his work is the page that he brought. - Pyramidheadecho json_encode($result), and handle ajax, and get it backvar values = JSON.parse($data)- teran