douzuita7325 2016-01-11 17:38
浏览 17

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>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 无线电能传输系统MATLAB仿真问题
    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
    • ¥15 关于#hadoop#的问题