首頁  >  文章  >  後端開發  >  购物车的浏览器兼容性问题

购物车的浏览器兼容性问题

WBOY
WBOY原創
2016-06-20 12:37:211062瀏覽

从网上找了个购物车,挺好用的,简单方便,可就是存在一个问题:不兼容IE6/IE7,点击“添加购物车”按钮没反应,而内网又存在大量的IE6,我看了一下,应该是html的兼容性问题,但就是找不到问题出在哪,大家帮忙看看:

购物车主程序:cart.php:
nbsp;html>

    


        订餐系统
        
        
        
    
    
        
  
            

Products

  
            
  
                        //current URL of the Page. cart_update.php redirects back to this URL  
            $current_url = base64_encode($url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);  
            require_once 'class/config.db.php';
            require_once 'class/db.php';
            $db=new db();
            $results = $db->query("SELECT * FROM cart ORDER BY id ASC");  
            if ($results) {

                //fetch results set as object and output HTML  
                while($obj = $db->fetch_object($results))  
                {
                    echo '
';   
                    echo '
';  
                    echo '
购物车的浏览器兼容性问题product_img_name.'">
';  
                    echo '

'.$obj->product_name.'

';  
                    echo '
'.$obj->product_desc.'
';  
                    echo '
';  
                    echo 'Price '.$currency.$obj->price.' | ';  
                    echo 'Qty ';  
                    echo '';  
                    echo '
';  
                    echo 'product_code.'" />';  
                    echo '';  
                    echo '';  
                    echo '
';  
                    echo '
';  
                }

            }
            ?>  
            
  

        
  
        

Your Shopping Cart

  
                if(isset($_SESSION["products"]))  
        {  
            $total = 0;  
            echo '
    ';  
                foreach ($_SESSION["products"] as $cart_itm)  
                {  
                    echo '
  1. ';  
                    echo '×';  
                    echo '

    '.$cart_itm["name"].'

    ';  
                    echo '
    P code : '.$cart_itm["code"].'
    ';  
                    echo '
    Qty : '.$cart_itm["qty"].'
    ';  
                    echo '
    Price :'.$currency.$cart_itm["price"].'
    ';  
                    echo '
  2. ';  
                    $subtotal = ($cart_itm["price"]*$cart_itm["qty"]);  
                    $total = ($total + $subtotal);  
                }  
                echo '
';  
            echo 'Total : '.$currency.$total.' Check-out!';  
            echo 'Empty Cart';  
        }else{  
            echo 'Your Cart is empty';  
        }  
        ?>  
        
  
        

    


提交按钮的链接,点按钮没反应。cart_update.php:
session_start();  
include_once("config.php");  
  
//empty cart by distroying current session  
if(isset($_GET["emptycart"]) && $_GET["emptycart"]==1)  
{  
    $return_url = base64_decode($_GET["return_url"]); //return url  
    session_destroy();  
    header('Location:'.$return_url);  
}  
  
//add item in shopping cart  
if(isset($_POST["type"]) && $_POST["type"]=='add')  
{  
    $product_code   = filter_var($_POST["product_code"], FILTER_SANITIZE_STRING); //product code  
    $product_qty    = filter_var($_POST["product_qty"], FILTER_SANITIZE_NUMBER_INT); //product code  
    $return_url     = base64_decode($_POST["return_url"]); //return url  
      
    //limit quantity for single product  
    if($product_qty > 10){  
        die('
This demo does not allowed more than 10 quantity!
Back To Products.
');  
    }  
  
    //MySqli query - get details of item from db using product code  
    $results = $mysqli->query("SELECT product_name,price FROM cart WHERE product_code='$product_code' LIMIT 1");  
    $obj = $results->fetch_object();  
      
    if ($results) { //we have the product info   
          
        //prepare array for the session variable  
        $new_product = array(array('name'=>$obj->product_name, 'code'=>$product_code, 'qty'=>$product_qty, 'price'=>$obj->price));  
          
        if(isset($_SESSION["products"])) //if we have the session  
        {  
            $found = false; //set found item to false  
              
            foreach ($_SESSION["products"] as $cart_itm) //loop through session array  
            {  
                if($cart_itm["code"] == $product_code){ //the item exist in array  
  
                    $product[] = array('name'=>$cart_itm["name"], 'code'=>$cart_itm["code"], 'qty'=>$product_qty, 'price'=>$cart_itm["price"]);  
                    $found = true;  
                }else{  
                    //item doesn't exist in the list, just retrive old info and prepare array for session var  
                    $product[] = array('name'=>$cart_itm["name"], 'code'=>$cart_itm["code"], 'qty'=>$cart_itm["qty"], 'price'=>$cart_itm["price"]); 
                } 
            } 
             
            if($found == false) //we didn't find item in array  
            {  
                //add new user item in array  
                $_SESSION["products"] = array_merge($product, $new_product);  
            }else{  
                //found user item in array list, and increased the quantity  
                $_SESSION["products"] = $product;  
            }  
              
        }else{  
            //create a new session var if does not exist  
            $_SESSION["products"] = $new_product;  
        }  
          
    }  
      
    //redirect back to original page  
    header('Location:'.$return_url);  
}  
  
//remove item from shopping cart  
if(isset($_GET["removep"]) && isset($_GET["return_url"]) && isset($_SESSION["products"]))  
{  
    $product_code   = $_GET["removep"]; //get the product code to remove  
    $return_url     = base64_decode($_GET["return_url"]); //get return url  
  
      
    foreach ($_SESSION["products"] as $cart_itm) //loop through session array var  
    {  
        if($cart_itm["code"]!=$product_code){ //item does,t exist in the list  
            $product[] = array('name'=>$cart_itm["name"], 'code'=>$cart_itm["code"], 'qty'=>$cart_itm["qty"], 'price'=>$cart_itm["price"]);  
        }  
          
        //create a new product list for cart  
        $_SESSION["products"] = $product;  
    }  
      
    //redirect back to original page  
    header('Location:'.$return_url);  
}  
?>  


回复讨论(解决方案)

你的表单没有提交按钮,且没有给出通过 js 提交的代码
所以任何浏览器都不可能产生表单提交动作

你的表单没有提交按钮,且没有给出通过 js 提交的代码
所以任何浏览器都不可能产生表单提交动作



解决了,是submit的事
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn