<?php
session_start();
include_once("config.php");
//current URL of the Page. cart_update.php redirects back to this URL
$current_url = urlencode($url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
?>
<!-- View Cart Box Start -->
<?php
if(isset($_SESSION["cart_products"]) && count($_SESSION["cart_products"])>0)
{
\t echo '<div class="cart-view-table-front" id="view-cart">';
\t echo '<h3>Your Shopping Cart</h3>';
\t echo '<form method="post" action="cart_update.php">';
\t echo '<table width="100%" cellpadding="6" cellspacing="0">';
\t echo '<tbody>';
\t $total =0;
\t $b = 0;
\t foreach ($_SESSION["cart_products"] as $cart_itm)
\t {
\t \t $product_name = $cart_itm["product_name"];
\t \t $product_qty = $cart_itm["product_qty"];
\t \t $product_price = $cart_itm["product_price"];
\t \t $product_code = $cart_itm["product_code"];;
\t \t $bg_color = ($b++%2==1) ? 'odd' : 'even'; //zebra stripe
\t \t echo '<tr class="'.$bg_color.'">';
\t \t echo '<td>Qty <input type="text" size="2" maxlength="2" name="product_qty['.$product_code.']" value="'.$product_qty.'" /></td>';
\t \t echo '<td>'.$product_name.'</td>';
\t \t echo '<td><input type="checkbox" name="remove_code[]" value="'.$product_code.'" /><strong>Remove</strong></td>';
\t \t echo '</tr>';
\t \t $subtotal = ($product_price * $product_qty);
\t \t $total = ($total + $subtotal);
\t }
\t echo '<td colspan="4">';
\t echo '<button type="submit">Update</button><a href="view_cart.html" class="button">Checkout</a>';
\t echo '</td>';
\t echo '</tbody>';
\t echo '</table>';
\t
\t $current_url = urlencode($url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
\t echo '<input type="hidden" name="return_url" value="'.$current_url.'" />';
\t echo '</form>';
\t echo '</div>';
}
?>
<!-- View Cart Box End -->
<!-- Products List Start -->
<?php
$results = $mysqli->query("SELECT product_code, product_name, product_desc, product_img, price FROM products ORDER BY id ASC");
if($results){
$products_item = '<ul class="products">';
//fetch results set as object and output HTML
while($obj = $results->fetch_object())
{
$products_item .= <<<EOT
\t <li class="product">
\t <form method="post" action="cart_update.php">
\t <div class="product-content"><h3><strong>{$obj->product_name}</strong></h3>
\t <div class="product_img"><img src="product_images/{$obj->product_img}"class="img-responsive img-thumbnail" width="150px" height="150px"></div>
\t <div class="product-desc">{$obj->product_desc}</div>
\t <div class="product-info">
\t \t <div class="product-price"><strong>
\t Price {$currency}{$obj->price}
\t </strong>
\t </div>
\t <fieldset>
\t <label>
\t \t <span>Quantity</span>
\t \t <input type="text" size="2" maxlength="2" name="product_qty" value="1" />
\t </label>
\t </fieldset>
\t <input type="hidden" name="product_code" value="{$obj->product_code}" />
\t <input type="hidden" name="type" value="add" />
\t <input type="hidden" name="return_url" value="{$current_url}" />
\t <div align="center"><button type="submit" class="add_to_cart">Add to cart</button></div>
\t </div></div>
\t </form>
\t </li>
EOT;
}
$products_item .= '</ul>';
echo $products_item;
}
?>
即時通訊開發一個電子商務網站後,PHP文件。我是新來的AJAX。我不知道如何解決這個問題。在index.html我把阿賈克斯代碼加載到html正文中的index.php。當我點擊 「添加到購物車」 「結賬」 「更新」 按鈕將它重定向到的index.php,而不是停留在的index.html。
更新*
<script >
function load_data(){
$.ajax({
url: "index.php",
dataType: 'html',
cache: false,
success: function(data){
$("#mydiv").html(data);
}
});
}
$(document).ready(function(){
load_data();
});
</script>
你不必有2個不同的頁面。 .php文件也可以包含html。這可能會解決您的問題。 –
但我也轉換我的網站到apk文件。所以我需要做一個HTML文件上傳到phonegap。感謝您的評論:) –
我明白,也不要使用間隔0000 ...你會崩潰客戶端,如果不是服務器。 –