2013-08-20 94 views
0

我需要修改网站,迫使我更新页面中的数据而不刷新其内容。系统应该改变,当访客输入零件号码时,显示一个单位的价格以及数量的折扣。 当访客选择一个可以让访客进行折扣的数量时,会显示一个新的价格和相应的折扣区域。 我们现在的系统工作正常,但它包括几个阶段,并且不会让用户在初始搜索阶段选择数量。 我需要使用jquery连接到数据库并获取所选数量的正确价格和折扣区域。 这里是需要改变的代码。如何更新页面数据,无需刷新页面,使用jQuery

<body > 


<table border="0" cellspacing="0" cellpadding="0" align="center"> 
<tr> 
<td align="center"> 

<?php 
include ("../includes/java_update.php"); 
?> 
<table width="100%" > 

         <?php 
    while ($row = mysql_fetch_array($result)) 
    { 
     // Increment the total cost of all items 
     ?> 
<tr class="inside1"> 
          <td colspan="8"><hr size="1" >        </td> 
         <tr id="inside"> 
          <td><input type="text" name="<?php echo $row["part_number"];?>" value="<?php echo $row["qty"];?>" id="t" onBlur="UpdateQty2(this.name,this.value)" size="3" >        </td> 
          <td><input name="button" type="button"value="Update" class="button"></td> 
           <td class="disc" width="12%" height="25"><?php echo $row["part_number"]; ?> </td> 
           <td class="discleft" width="39%" height="25"> 
<?php 



          echo $row["disc"]; ?>        </td> 
          <td id="price" width="6%" height="25">&pound; 
           <?php 

          for($in =1 ; $in <= 8; $in++) 
          { 
          $bb=$row["price_break".($in)]; 

          $halves =explode("-",$bb); 
          $firstnumber=$halves[0]; 
          $secondnumber=$halves[1]; 




         If ($row["qty"] >= $firstnumber && $row["qty"] <= $secondnumber) 

         { 
         echo number_format($row[("price_each".$in)], 2, ".", ","); 


        tprice ($row["part_number"],$row[("price_each".$in)],$row[("qty")]); 
        //echo"part_number is ".$row["part_number"]; 
        //echo "<br>"; 
        //echo"price_each is ".$row[("price_each".$in)]; 


         $which=$in; 

         $totalCost += ($row["qty"] * $row[("price_each".$which)]); 
         } 


          } 



           ?>       </td> 
          <td align="center" class="in_stock"> 

          </td> 
          <td width="9%" height="25" class="pblist" ><select name="pb" > 
           <?php 


         $c=$row["price_each1"];// price for single item 


          for($i = 1; $i <= 8; $i++) 
          { 


          $b=$row["price_each".$i]; 


          if ($b !=0.00) 
           { 

           $d=(($c-$b)/$c)*100; 



          $complete=$row[("price_break".$i)]. " ," .round($d)."%";  
        echo "<option "; 


          if ($i == $which) 
            { 
             echo " SELECTED "; 
            } 
          echo ">". $complete ."</option>";  



          } 
          } 


          ?> 
          </select>        </td> 
          <td id="removeit"><a id="removeit" href="cart_wp.php? action=remove_item&id=<?php echo $row["part_number"]; ?>">Remove</a> </td> 
         </tr> 

<script type="text/javascript"> 

function UpdateQty2(s,m) 
      { 
     var part_number=s; 




     if (isNaN (m)) { 
    // Not A Number 
    alert('Please enter a valid no.') ; 
} else { 


     var newQty=m; 


     document.location.href = 'cart_wp.php?action=update_item&id='+part_number+'&qty='+newQty; 
     } 


    } 

+0

缩进及重新格式化您的代码首先,请 – AdityaSaxena

回答

2

$.post()文档

$.ajax({ 
    type: "POST", 
    url: url, 
    data: data, 
    success: success, 
    dataType: dataType 
});