S
S
sickgang2020-06-12 15:14:19
1C-Bitrix
sickgang, 2020-06-12 15:14:19

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);
        });


Here is the code in the template.php file
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>


I don’t understand why it’s impossible to accept this variable, either I’m doing something with Bitrix, or I’m doing something wrong.
Or somehow, when selecting select, you can get the id and put it in CIBlockSection::GetList().
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shamanov, 2020-06-12
@SilenceOfWinter

<option selected value=0"">

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question