Populate numbered buttons with jquery $ .post ()

I am using jquery $.post()

to call data. Everything works fine. My question is, how can I create buttons for the amount of data returned?

  var i = 0;
  $.post('getFruits.php',
        {
          category:fruits
        },
      function(data){
        i++;
        += '<button type="button" class="small">i</button>';
   });

      

PHP:

$data['pages'] = $pgs;
echo json_encode($data);

      

+3


source to share


1 answer


Do it like this



  $.post('getFruits.php',
            {
                category: fruits
            },
    function (data) {

        var buttons="";

        returned_data = JSON.parse(data);
        for(i = 0; i <= returned_data.pages; i++){
            buttons +='<button type="button" class="small">Button number '+i+'</button>';
        }



    });

      

0


source







All Articles