私は小さなeコマースウェブサイトを構築しようとしています。今ではjqueryプログラムでカートのアイテムを計算したので、合計のこれらのアイテムは、最初のものの隣に印刷します。だから私は私のソースコードをチェックアウトし、Googleのクロムの私のjsファイルをネットワーク、私は量が正しく計算されているが表示されませんが表示されます。jquery総額を計算しますが表示しません
私のhtmlのスパン:(合計金額を表示する):
<span id="total12"><?php echo $_SESSION['total'];?></span>
マイaddpanier.phpファイル:
<?php
session_start();
require 'connexion.php';
require 'panier.php';
$json=array('error' => true);
$panier=new panier();
try {
$con1 = new myPDO();
}
catch (PDOException $e) {
echo "<br/> Erreur: ".$e->getMessage()."<br/>" ;
die() ;
}
if (isset($_GET['id'])) {
$bdd = $con1->prepare("SELECT * FROM article a,promotion p WHERE a.id=p.id_article HAVING a.id=?") ;
$bdd->bindValue(1,$_GET["id"]);
$bdd->execute();
$result = $bdd->fetch(PDO::FETCH_ASSOC);
$tot2=0;
if (empty($result)) {
$json['message']="produit introuvable!";
}else{
$panier->add($result["id"]);
$json['error']= false;
if (isset($_SESSION['panier'])) {
$tot=0;
$tot=$result["prix"]*$_SESSION['panier'][$result["id"]];
$b=$tot-$tot*($result["rabais"]/100)+$result["tax"];
$tot2+=$b;
}else{
$tot=0;
$tot=$result["prix"];
$b=$tot-$tot*($result["rabais"]/100)+$result["tax"];
$tot2+=$b;
}
$json['total1']=$tot2;
$json['panier']= array_sum($_SESSION['panier']);
$json['message']='produit bien ajoute a votre panier !';
}
}else{
$json['message']="pas de produits a ajouter au panier";
}
echo json_encode($json);
?>
そして、私のjqueryのファイル:
ここに私のコードです(function($){
$('.addpanier').click(function(event){
event.preventDefault();
$.get($(this).attr('href'),{},function(data){
if (data.error) {
alert(data.message);
}else{
if(confirm(data.message + '. Voulez vous consulter votre panier?')){
location.href="product_summary.php";
}else{
$('#panier12').empty().append(data.panier);
$('#total12').empty().append(data.total1);
}
}
},'json');
return false;
});
})(jQuery);
申し訳ありませんが、動作していません... –
さて、セレクタに問題があるか、値が未定義です。このようにデバッグするのは難しいですが、あなたがそれを更新するのを見るでしょう... – WalksAway
開発者のコンソールを開き、コードブロック – WalksAway