Answer the question
In order to leave comments, you need to log in
How to properly pass selected value by ajax request to php file?
Hello!
I can’t figure it out, there is a select with several option values, each option has an id with a unique value.
When choosing a certain option, using ajax request, I send this value to the template of the sale.order.ajax component, but when displaying it in this template, or checking if this variable exists, nothing happens, here is the code:
jQuery
$("#cart-part_region").change(function(){
if($("#cart-part_region option:selected").val() !== '0'){
let id = $("#cart-part_region option:selected").val();
$.post('/local/templates/eshop_bootstrap_v4/components/bitrix/sale.order.ajax/bootstrap_v4/template.php', {id: id}, function(data) {
$('.cart-part_city').show();
alert(id);
});
echo ($_POST['id']);
?>
<div class="cart-part_city">
<div class="cart-part_form-name mb-3">
<span>Город:</span>
</div>
<div>
<select id="cart-part_city">
<option selected value=0"">-</option>
</select>
</div>
</div>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question