如何使用jQuery更新页面数据,而无需刷新页面

时间:2013-08-20 09:07:18

标签: 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;
        }


    }

1 个答案:

答案 0 :(得分:2)

$.post()文档

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