javascript - how to recover and pass multiple php variables in my AJAX call

one text

I need to pass my PHP variables defined (earlier in my page) in my Ajax call.

And I have a lot of variables defined so I cannot do it var by var in my code.

My first question is, is there a way in PHP to loop on every defined variable ? like get my $var1, $var2

I think I could do it earlier in my PHP page between <script> tags but this is really not clean.

My AJAX call is like so:

function add_content_in_divs(class_name, target_div) {

   var page_name = 'displayer/' + class_name + '_informations.php'

   $.ajax({
      url:page_name,
      type: 'GET',
      data: {//need to pass my PHP vars here},

         success: function (resp){
            target_div.html(resp);
         }

   })
}

My final goal is to include a part of PHP code in my div, knowing that this include contains $vars defined in my main PHP page. So my includes parts of code doesn't recognize my PHP vars in.

There is an example of code part I have to include.

if (isset($detail)) {

    echo '<div class="row"><span class="font-weight-bold">City detail: </span>' . $detail . '</div>';

} 

Source