Good day.

Is it possible through the script to change the value of the variable php?

There is a menu:

<button type="button" class="btn btn-sky text-uppercase btn-sm" id="btn_p"></button> <button type="button" class="btn btn-sky text-uppercase btn-sm" id="btn_m"></button> <button type="button" class="btn btn-sky text-uppercase btn-sm" id="btn_w"></button> <button type="button" class="btn btn-sky text-uppercase btn-sm" id="btn_s"></button> <button type="button" class="btn btn-sky text-uppercase btn-sm" id="btn_i"></button> 

Below with php:

 $news = new RSS_Pars($url) 

Is it possible to realize that when you click each of the menu buttons, it supplies its url to a variable? If so, how?

Thanks in advance for your help.

    1 answer 1

    You should understand that PHP is a server, js is a client. The server has already given the data in the response, and the process is complete. All PHP variables are already in the past. To do something in PHP, you need to create another query. Without refreshing the page this is AJAX .

    UPD:

     <button type="button" class="btn ..." data-link="http://link1.com"></button> <button type="button" class="btn ..." data-link="http://link2.com"></button> <script> $('button').click(function(){ //при клике $.ajax({ //отправляем ajax-запрос type: "POST", //тип (POST, GET, PUT, etc) url: "/Your/Handler/Url/", //УРЛ Вашего обработчика data: { xmlUrl: $(this).attr('data-link') } //сами данные, передается POST[xmlUrl] со значением из data-link нажатой кнопки }) .done(function( res ) { //при успехе (200 статус) $('#result').html(res) //заменяем блок с id="result" полученной строкой от сервера. }); }); </script> 

    In the PHP script itself, at the address /Your/Handler/Url/ generate HTML to return to the client. In general, you can form and JSON, and everything that you want that it is more convenient for you to process on the client for issue. What you build will come in the variable res.

    • I would have an example of such a task, it would be great. - Shadow33
    • Their heaps on the Internet. Google "ajax examples". From the question is not entirely clear what you need. - A1essandro
    • I pass the address of the xml file to $ url and parse it, output what I need. but there are a lot of xml files so I want to implement a menu where the $ url value changed when the button was pressed, and another file is already being parsed and displayed. - Shadow33