Good day. I transfer two variables to the ajax function in a php file.
function selectCategory(){ var category_id = $('select[name="category_id"]').val(); if(!category_id){ $('div[name="selectCategory"]').html(''); }else{ $.ajax({ type: "POST", url: "/ajax.base.php", data: { action: 'showRegionForInsert', category_id: category_id }, cache: false, success: function(responce){ $('div[name="selectCategory"]').html(responce); } }); }; };
At the same time, the action variable is processed and the file sees it, but category_id does not.
In the network tab of the php file, the headers in the form data section contain the values of both variables, but for some reason it does not see the file. Here is the php file
$db = new PDO("mysql:host=localhost;dbname=gz_database_main","root",""); $sql = 'SELECT id, name FROM category WHERE status = "1" and parent IS NOT NULL and parent = :category_id'; $result = $db->prepare($sql); $result->bindParam(':category_id', intval($_POST['$category_id']), PDO::PARAM_INT); $result->execute(); // Получение и возврат результатов $i = 0; $categoryList = array(); while ($row = $result->fetch()) { $categoryList[$i]['id'] = $row['id']; $categoryList[$i]['name'] = $row['name']; $i++; } echo '<select name="pod_category_id" id="pod_category_id" class="form-control">'; foreach ($categoryList as $listCateg) { echo '<option value="'.$listCateg['id'].'">'.$listCateg['name'].'</option>'; }; echo '</select>';