D
D
DDias2020-11-25 15:15:03
PHP
DDias, 2020-11-25 15:15:03

Through the function I receive JSON and I need to draw it and bind it to the buttons, how to do this?

Through this function I get JSON

function GetServices(type,region_id,group_id)
{

jQuery.ajax({
method: "POST",
url:"",
data:"?&region_id="+region_id+"&type="+type+"&group_id="+group_id,
success: function (html){

var obj = JSON.parse(html);
jQuery("#temp").html("");
jQuery.each(obj, function(index, value) {
jQuery("#temp").append("service_id:"+service_id+", name:"+value.name+"");
});
}
});

}

And you need to bind this data to HTML buttons by service_id

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nazariy Lazarchuk, 2020-11-25
@LazarchukNazar

DDias , in this case, you need to create an event handler (Event) on the buttons. In this case, the "click" event will probably suit you.

// находим на сайте ссылку на кнопку
  const button1 = document.querySelector('CSS-селектор на кнопку');

  // делаем обработчик события
  button1.addEventListener('click', function(e) {
      console.log('Случилось событие клик на кнопку');
      // тут делаем всё что касаеться "привязки"
  });

In order to save data from your Ajax, store the response in some object

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question