php - jQuery is working on click of Cancel Button -


i have 1 class reference stock function. , have file contain php , jquery. in php code check if product in stock equal zero, confirm box pop up. problem when click on cancel button, ajax still run function of class , update data in database observed alert success did not load. how fix? sorry bad english.

php file:

<?php if($record['product_in_stock']<=0){?>             <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>                        <script type="text/javascript" language="javascript">                         if(confirm('product in stock empty now, want continue?')){                                 alert('ok');                                var order_id="12059";                                 $.ajax({                                     url:'components/com_virtuemart/classes/check_product_instock.php',                                     type:'post',                                     data: order_id,                                     success: function(){                                         alert(success);                                      }                                 });                              return true;                           }else{                                 alert('no');                                return false;                           }                           </script> <?php }?> 

check_product_instock.php class

    <?php if( !defined( '_valid_mos' ) && !defined( '_jexec' ) ) die( 'direct access '.basename(__file__).' not allowed.' ); class checkstock{     private $order_id; function getorderid(){     if(isset($_post['order_id'])){         $this->order_id=$_post['order_id'];      } } function check(){  if(isset($_post) && $_post['order_id']>0){  $order_id=$_post['order_id'];          $q = "select product_id, product_quantity jos_vm_order_item order_id='".$order_id."'";               $result=mysql_query($q);               while ($record=mysql_fetch_array($result)) {                   $q = "update jos_vm_product                       set product_in_stock=product_in_stock - ".$record["product_quantity"].",                       product_sales=product_sales + ".$record["product_quantity"]."                       product_id=".$record["product_id"];                       mysql_query($q);                }          }     } } $stock = new checkstock(); $stock->check(); 

  • firstly, think don't require return true , return false in if condition.

  • secondly, have pass parameter in ajax function such data : 'order_id =' + order_id,. php file(check_product_instock.php) can read post value.


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -