Assistance is required in resolving the issue of queries to the database and their display on the html page. There is a request with two parameters: p1 and: p2, I collect these parameters with 2 value in 2 drop-down html lists. It is necessary that when selecting the 2 desired positions and clicking on the button, a query was made to the database and immediately output data from there to the html form. What is the best way to do this?

So far, only managed to return the collected data from these 2 lists.

$(function () { $("form").bind('submit', function (e) { e.preventDefault(); var form = $("form").serialize(); $("#results").text(form); var form = $(this), serialize = form.serialize(); }); }); 

I just can’t figure out how to transfer data from JS to a PHP script and how to substitute them there in the values: p1 and: p2, and even so that it all works asynchronously.

    3 answers 3

    Look in the direction of my answer, ajax request by reference .

    In data: you will need to send your data from the form:

     data: { 'form_data': form } 

    In php: catch by key form_data .

      Bro, krch you need to create a .php file in which there will be a query in the database with the necessary query. You will take 2 values ​​from the $ _POST jquery request, assign it in the .php file

       if($_POST){ $table = $_POST['значение_1']; $mailVariable = $_POST['значение_2']; а ниже любой запрос в бд с использованием переменных. 

      Also in the file where you take this variable (in .js) you write
      $.post( "test.php", { name: "переменная_1", time: "переменная_2" },function(){//выполнить в случае успеха} ); Clear? It seems so ... And you will also need to work with JSON files and fetch in that php file, then you will return from the request to the database and then return the file / html file to the .js file where the ajax post request. Krch to explain a lot - google ajax php mysql

        Thank you all very much for your help. If someone comes in handy:

        JS: Here I collect values ​​from 2 selections in html

         $('#button').click(function() { var name1 = $('#name1').val(); var name2 = $('#name2').val(); $.ajax({ url: 'config.php', data: { 'name1': +name1, 'name2': +name2 }, error: function(jqXHR, textStatus, errorThrown) { alert('Не удалось выполнить запрос'); //$("#results").text(textStatus); }, success: function(data, textStatus) { //$("#results1").text(textStatus); $('#content').text(data); } }); }); 

        php: Just returning it back

         if(isset($_GET['name1'])) { echo $name = $_GET['name1']; } if(isset($_GET['name2'])) { echo $name = $_GET['name2']; exit(); }