2016-11-17 3 views
0

の.htmlファイルには、Imはeコマースのウェブサイトを開発

<?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私は、index.phpをHTML本体の中にロードするためにajaxコードを入れました。私がクリックしたときと "チェックアウト" "更新" index.phpをへのリダイレクトは、代わりにindex.htmlをに滞在ボタン "はカートに追加します"。

UPDATED *

<script > 
function load_data(){ 
     $.ajax({ 
      url: "index.php", 
      dataType: 'html', 
      cache: false, 
      success: function(data){ 
      $("#mydiv").html(data); 
      } 
     }); 
} 
$(document).ready(function(){ 
load_data(); 
}); 
</script> 

index.htmlindex.php

+0

を参照してください。 .phpファイルにもhtmlを含めることができます。それはあなたの問題を解決するかもしれません。 –

+0

でも、私のウェブサイトをapkファイルに変換しています。だから、私はそれをphonegapにアップロードするためにhtmlファイルを作る必要があります。コメントありがとう:) –

+0

私は理解し、また0000の間隔を使用しない...あなたはクラッシュし、クライアントではない場合はサーバー。 –

答えて

0

jQueryの$アヤックス()関数は、非同期HTTPリクエストを実行するために使用されます。これは、バージョン1.0以来ずっと前にライブラリに追加されました。 $ .ajax()関数は、前述の記事で説明したすべての関数が、あらかじめ設定された設定を使ってシーンの後ろを呼び出しているものです。この関数のシグネチャは以下のとおりです。オプションはリテラルのAjaxリクエストのための設定を含むオブジェクトである一方、

$.ajax(url[, options]) 
$.ajax([options]) 

urlパラメータは、あなたがAjax呼び出しに到達したいURLを含む文字列です。

最初の形式では、この関数はurlパラメータとoptionsで指定されたオプションを使用してAjaxリクエストを実行します。 2番目の形式では、URLはoptionsパラメータで指定されます。省略することもできますが、その場合は現在のページに対して要求が行われます。

setInterval()メソッドは、指定された間隔(ミリ秒単位)で関数を呼び出したり、式を評価したりします。

あなたのケースでは、あなたのコードは、

$(document).ready(function(){ 
      auto_load(); 
     }); 
    setInterval(auto_load,10000); 
function auto_load(){ 
    $.ajax({ 
     url: 'path/to/file/index.php', 
     data: { 
      format: 'json' 
     }, 
     error: function() { 
      $('#info').html('<p>An error has occurred</p>'); 
     }, 
     dataType: 'jsonp', 
     success: function(data) { 
     alert(data); 
     //auto_load(); your code assignment and result goes here 
     }, 
     type: 'GET' 
    }); 
} 

でなければならず、また、あなたが2つの異なるページを用意する必要はありませんhttps://www.sitepoint.com/use-jquerys-ajax-function/

+0

ありがとう..しかし、まだ動作しませんし、ページが空白です:( –

+0

結果が欲しい場合は、auto_load()関数をコメントして、結果を得る必要があります –

関連する問題