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

时间:2016-01-11 17:38:06

标签: javascript php json

我的PHP文件处理网络和移动设备。 Javascript文件将ajax / json定向到mobile.html。使用mobile.html时,JSON会在HTML代码开始之前返回到PHP代码的末尾。 JSON returned to wrong HTML 我粘贴了代码影响。我是学生,如果我的帖子令人困惑,请让我提前道歉。

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>

米/ e43qk.jpg

0 个答案:

没有答案