Jump to content

My Ajax button doesn't work everytime...why?


cyberspiritual

Recommended Posts

Hi Guys...!

 

I need help .

 

I have an Oscommerce shop and have installed 2 Ajax contribution. (Ajax add to shopping cart & Ajax Shopping cart)

 

But now I want to be able to put on the product page a message like:

You have currently XXX units of this item in your shopping cart.

 

But I have a problem, my ajax code doesn't always follow the shopping cart number.

Take a look:

http://www.khe  opsinternational.ca/catalog/product_info.php?products_id=1036 (remove the space)

 

Can you please help me...many thank's

 

Here's my javascript:

<script type="text/javascript" src="prototype.js"></script>
      <script>

         function sendRequest() {
            new Ajax.Request("qtydanscart.php?superid=<?php echo $superid ?>", 
               { 
               onComplete: showResponse 
               });
            }


         function showResponse(req){
            $('show').innerHTML= req.responseText;
         }

      </script>

 

Here's by button code:

// Output a form
  function tep_draw_form($name, $action, $method = 'post', $parameters = '') {
    $form = '<form name="' . tep_output_string($name) . '" action="' . tep_output_string($action) . '" method="' . tep_output_string($method) . '"';

    if (tep_not_null($parameters)) $form .= ' ' . $parameters;
// AJAX Addto shopping_cart - Begin
    if( preg_match("/add_product/i", $action) ){
      $form .= ' onSubmit="doAddProduct(this); sendRequest(); return false;"';
    }
  // AJAX Addto shopping_cart - End
    $form .= '>';

    return $form;
  }

 

Here's my "DIV":

<div id="show">
<?php 
$superid = $product_info['products_id'];
$products = $cart->get_products();
for ($i=0, $n=sizeof($products); $i<$n; $i++) {
if ($products[$i]['id'] == $superid) {
$qtyincart = $products[$i]['quantity'];
echo"<b>$qtyincart</b> units in cart.    ";
break;
}
}?></div>

 

and here's my PHP (qtydanscart.php):

<?php
require('includes/application_top.php');

$superid = $_GET['superid'];
$products = $cart->get_products();
for ($i=0, $n=sizeof($products); $i<$n; $i++) {
if ($products[$i]['id'] == $superid) {
$qtyincart = $products[$i]['quantity'];
echo"<b>$qtyincart</b> units in cart.    ";
break;
}
}
?>

 

Thank's

 

 

So,

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.