2016-04-11 22 views
0

Ücretsiz indir "Ustora" şablonu (eTicaret için html teması) ile çalışıyorum. Aynı zamanda, tek ürün sayfasında "Sepete ekle" düğmesiyle çalışıyorum. Tıkladıktan sonra ürün verilerini veri tabanımdaki sepet tablomuza ekleyecek bir ajax işlevi başlatmalıdır. Ama bu işe yaramıyor.ajax alışveriş sepetinde çalışmaya devam ediyor

E-ticaret web sitesini oluşturmayı öğrenmek için bununla çalışıyorum. Lütfen aşağıda en erken yardım kodum aşağıda yazınız.

Tek ürün-page.php

   <?php 
       $row = mysql_fetch_row(mysql_query("SELECT * FROM `products` where pid='".$_GET['proid']."' ")); 
       echo '<div class="row"> 
        <div class="col-sm-6"> 
         <div class="product-images"> 
          <div class="product-main-img"> 
           <img src="'.$row[5].'" alt="'.$row[2].'"> 
          </div> 

          <div class="product-gallery"> 
           <img src="'.$row[5].'" alt="'.$row[2].'"> 
           <img src="'.$row[5].'" alt="'.$row[2].'"> 
           <img src="'.$row[5].'" alt="'.$row[2].'"> 
          </div> 
         </div> 
        </div> 

        <div class="col-sm-6"> 
         <div class="product-inner"> 
          <h2 class="product-name">'.$row[2].'</h2> 
          <div class="product-inner-price"> 
           <ins>'.$row[3].'/- INR</ins> <del>'.$row[3].'/- INR</del> 
          </div>  

          <form method="post"> 
           <div class="quantity"> 
            <input type="number" size="4" class="input-text qty text" title="Qty" value="1" name="quantity" id="qty" min="1" step="1" max='.$row[6].'> 
           </div> 
           <button class="add_to_cart_button" onclick="addtocart('.$row[1].','.$row[2].','.$row[3].','.$buid.');"> 
            Add to cart 
           </button> 
          </form> 

          <div class="product-inner-category"> 
           <p>Category: <a href="">Summer</a>. Tags: <a href="">awesome</a>, <a href="">best</a>, <a href="">sale</a>, <a href="">shoes</a>. </p> 
          </div> 

          <div role="tabpanel"> 
           <ul class="product-tab" role="tablist"> 
            <li role="presentation" class="active"><a href="#home" aria-controls="home" role="tab" data-toggle="tab">Description</a></li> 
            <li role="presentation"><a href="#profile" aria-controls="profile" role="tab" data-toggle="tab">Reviews</a></li> 
           </ul> 
           <div class="tab-content"> 
            <div role="tabpanel" class="tab-pane fade in active" id="home"> 
             <h2>Product Description</h2> 
             '.$row[4].' 
             </div> 
            <div role="tabpanel" class="tab-pane fade" id="profile"> 
             <h2>Reviews</h2> 
             <div class="submit-review"> 
              <p><label for="name">Name</label> <input name="name" type="text"></p> 
              <p><label for="email">Email</label> <input name="email" type="email"></p> 
              <div class="rating-chooser"> 
               <p>Your rating</p> 

               <div class="rating-wrap-post"> 
                <i class="fa fa-star"></i> 
                <i class="fa fa-star"></i> 
                <i class="fa fa-star"></i> 
                <i class="fa fa-star"></i> 
                <i class="fa fa-star"></i> 
               </div> 
              </div> 
              <p><label for="review">Your review</label> <textarea name="review" id="" cols="30" rows="10"></textarea></p> 
              <p><input type="submit" value="Submit"></p> 
             </div> 
            </div> 
           </div> 
          </div> 

         </div> 
        </div> 


       </div>'; 

       ?> 

header.php Sadece Sepete Ekle" konulu addToCart() fonksiyonunu başlatmak istiyorum

<!DOCTYPE html> 
<html lang="en"> 
    <head> 
    <meta charset="utf-8"> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <title>Product Page - Ustora Demo</title> 

    <!-- Google Fonts --> 
    <link href='http://fonts.googleapis.com/css?family=Titillium+Web:400,200,300,700,600' rel='stylesheet' type='text/css'> 
    <link href='http://fonts.googleapis.com/css?family=Roboto+Condensed:400,700,300' rel='stylesheet' type='text/css'> 
    <link href='http://fonts.googleapis.com/css?family=Raleway:400,100' rel='stylesheet' type='text/css'> 
    <script src="jquery.js"></script> 


    <script type="text/javascript"> 
    function addtocart(pid,name,price,buid) 
    { 
     alert("addToCart function working"); 
    var pid = pid; 
    var pname = name; 
    var pprice = price; 
    var pqty = document.getElementById("qty").value; //$(#qty).val(); 
    var buid = buid; 

    //var cstid = $(#).val(); 
    $.ajax({ 
      type:"POST", 
      url:"http://localhost/phpsales/insert-cart.php", 
      data:{pid,pname,pprice,pqty,buid}, 
      cache:false, 
      success:alert("Product Added Successfully") 
      //error:function fail(){alert("Some technical error occured dufine product add to cart. Please try after some time.");} 
     }); 
    } 
    </script> 


    <!-- Bootstrap --> 
    <link rel="stylesheet" href="css/bootstrap.min.css"> 

    <!-- Font Awesome --> 
    <link rel="stylesheet" href="css/font-awesome.min.css"> 

    <!-- Custom CSS --> 
    <link rel="stylesheet" href="css/owl.carousel.css"> 
    <link rel="stylesheet" href="style.css"> 
    <link rel="stylesheet" href="css/responsive.css"> 

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> 
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// --> 
    <!--[if lt IE 9]> 
     <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script> 
     <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> 
    <![endif]--> 
    </head> 
    <body> 

"düğmesini tıklayın ve alışveriş sepetine veri eklemek istedikten sonra. peşin

Teşekkür

+1

Konsol hatasını kontrol ettiniz mi? – uzaif

+0

"addToCart işlevi çalışıyor" uyarısını mı alıyorsunuz ya da vermiyor musunuz? –

+0

hayır Uyarı ("addToCart işlev çalışıyor") iletisini alamıyorum. – Web7

cevap

0

i sorun

function addtocart(pid,name,price,buid) 
    { 
    alert("addToCart function working"); 
    var pid = pid; 
    var pname = name; 
    var pprice = price; 
    var pqty = document.getElementById("qty").value; //$(#qty).val(); 
    var buid = buid; 

    //var cstid = $(#).val(); 
    $.ajax({ 
      type:"POST", 
      url:"http://localhost/phpsales/insert-cart.php", 
      data:{pid,pname,pprice,pqty,buid},//here is the problem 
      data:{pid:pid,pname:pname,pprice:pprice,pqty:pqty,buid:build},//this must be like this 
      cache:false, 
      success:alert("Product Added Successfully") 
      //error:function fail(){alert("Some technical error occured dufine product add to cart. Please try after some time.");} 
     }); 
    } 
+0

Ancak bu bir ilk uyarı uyarısı bile uyarı değil ("addToCart işlev çalışıyor") ;. – Web7

+0

parametre değerlerinizi belirtin, daha sonra @Vicky işaretlerini de çözmeniz gerekir –

0

seni o kadar gibi addToCard() işlevini çağırarak Tartışmalarınızın tırnak koymak gerektiğini düşünüyorum yeni sayfaya veri gönderen verilerde olduğunu düşünüyorum:

+0

teşekkürler ama bu teknik, veriyi gösteren instocart() fonksiyonunda inspecart() fonksiyonunda – Web7

+0

çalışmıyor. Bunun gibi onclick = "addtocart (10001, Samsung Galaxy s5- 2015, 2400,8kufj1umpgn3537n8qmh0hr1e3);" – Web7

+0

Şimdi iyi olmalı, sadece değerlerin etrafına tırnak koymayı ve doğru bir şekilde kaçmayı denemeliyim. –

İlgili konular