JSON返回到PHP代码的末尾而不是mobile.html

My PHP file processes for both web and mobile. Javascript file directs the ajax/json to mobile.html. When using the mobile.html, JSON returns to the end of the PHP code, before the HTML code begins. JSON returned to wrong HTML I pasted the code affect. I am a student and let me apologize in advance if my post is confusing.

function getProductPerdomo() {   
    var cigarName = "";
    var price = ""
    var supplyAmount = "";
    $.ajax({                 
            url: 'selectperdomo.php', 
            type: 'POST',
            dataType: "JSON",   
            data: {   
                mobile: "yes" 
            },
            success: function(json){   
            $.each(json, function(key, value){   
                cigarName = value.cigar_name;
                price = "Price: " + value.price;
                supplyAmount = "In Stock: " + value.supply;  
            });
         $('#perdomonamehere').html(cigarName);
         $('#perdomopricehere').html(price);
         $('#perdomosupplyhere').html(supplyAmount);  
        }
    })
}  
<?php
            $mobile = $_POST["mobile"]; 
            if ($mobile == "yes"){
                 $price=199;
            $sql = "SELECT cigar_name, price, supply
                    FROM product T1
                    INNER JOIN inventory T2 ON T1.cigar_id=T2.cigar_id
                    WHERE price=$price";
                     
            $result = mysqli_query($conn, $sql);
                $data = array();   
            while($r = mysqli_fetch_assoc($result)) {    
                $data[] = $r;
            }
                echo json_encode($data);
            }else{
            
$_SESSION["price"] = 199;  
$_SESSION["cigar_id"] = 4;  //this is for perdomo

            $sql = "SELECT supply FROM inventory WHERE cigar_id=4";
            $result = mysqli_query($conn, $sql);

            if (mysqli_num_rows($result) > 0){
                while ($row = mysqli_fetch_assoc($result)){
                    
            echo "<table> <tr>
                          <td>Number of Boxes in Stock:  " . $row["supply"] .   "  </td>
                          </tr>                          
                </table>";
                }
            }
            else{
                echo "0 results";
            }
     } //end else  
?>

<!DOCTYPE html>
<html lang="en-US">
     <head>
<div data-role="page" data-dialog="true"  id="perdomo">
  <div data-role="header">
  <a href="#" class="ui-btn ui-icon-back ui-btn-icon-left" data-rel="back">Back</a>
  <h1>Products</h1>
  </div>
 <div data-role="main" class="ui-content">
 <p id="perdomonamehere"></p>
 <p id="perdomopricehere"></p>
 <p>Box of 24</p>
 <p id="perdomosupplyhere"></p>
    <form method="post">
      <div class="ui-field-contain">
        <label for="quantity">Quantity:</label>
        <input type="number" name="quantity" id="perdomoquantity" >   
      </div>
      <input type="submit" data-inline="true" value="Submit">
    </form>
  </div>
</div>

m/e43qk.jpg

</div>