J'essaie de créer un site de panier. Lorsqu'un utilisateur clique sur ajouter à l'image du panier sur la page du produit, le titre du produit affiche un texte "Le produit est dans votre panier" sans recharger la page. J'utilise la session et l'ajax mais pas de chance jusqu'ici. J'apprécie toute aide.De toute façon que je peux obtenir les valeurs d'un tableau PHP par ajax?
Mon html froid
<table id="<?php echo $productId; ?>" width="594" border="0" cellpadding="5" cellspacing="0">
<tr>
<td><img src="<?php echo "$brandImage"; ?></td>
<td <?php echo $productName; ?> //The "The product is in your cart" will be showed here</td>
</tr>
<tr>
<td><a class="addToCart" href="javascript:void(0);" onclick="addToCart(<?php echo $productId?>)">
</td>
Mon fichier Javascript (de addToCart.js)
function addToCart(productId){
var url="addToCart.php";
url=url+"?productId="+productId;
url=url+"&sid="+Math.random();
$.post(
url,
function(responseText){
alert(responseText); //I wish I can get productData value from addToCart.php
},
"html"
)
Mon fichier php (addToCart.php)
<?php SESSION_START();
$productId=$_GET['productId'];
$cart=$_SESSION['cart'];
if(isset($cart)){
$cart.=",".$productId;
$product=explode(',',$cart);
$totalItem=count($product);
}else{
$cart=$productId;
$totalItem=1;
};
$productData=array();
foreach($product as $id){
$productData[$id]=(isset($productData[$id])) ? $productData[$id]+1 :1;
};
$_SESSION['cart']=$cart;
//print_r($productData);
echo $productData; //Not sure what to do to send $productData back to my addToCart.js variable
?>
J'ai essayé pour rendre le code simple. Toute suggestion sera une aide précieuse. Merci
J'aime votre HTML * froid *: P – alex
lol ...... A BESOIN DE CONTRÔLE D'ÉPREUVE! .. – FlyingCat