M
M
marq2021-10-09 12:38:09
AJAX
marq, 2021-10-09 12:38:09

How to get select value by ajax in PHP file?

Good afternoon, I can not figure out how to get the select value in the php file and send it back

div id="message"></div>
  <select id="select">
    <option value="black">Черный</option>
    <option value="white">Белый</option>
    <option value="red">Красный</option>
</select>


$(document).ready(function () 
{
    $('#select').on('change', function () 
    {
        if ($('#select').val() === null) {              
            alert("Error");
        }
        else
        {
            var selectedValue = $('#select').val();


            $.ajax
            ({
                url: 'index.php',
                type: 'POST',
                data: 'espace_id=' + selectedValue,
                success: function(data) 
                {
                   	$('#message').html(selectedValue);
                }
            });
        }
    });
});

from this example, I get data and immediately display it, but I can’t figure out how to insert it in php

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
lil_koi, 2021-10-09
@lil_koi

var selectedValue = $('#select').val();
Here you got what you chose from the select.
I have little understanding of what it means to "write" in php, so I don't know how to help

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question