search
HomeCMS TutorialEmpire CMSOne trick to solve the problem of Imperial ECMS's method of adding AJAX to the shopping cart without refreshing

One trick to solve the problem of Imperial ECMS's method of adding AJAX to the shopping cart without refreshing

The main steps for Imperial ECMS to implement AJAX-free adding to the shopping cart are as follows:

1. Modify the mall content template and add the following code to the head:

The code is as follows:

<script type="text/javascript" src="[!--news.url--]skin/default/js/jquery.js"></script>
<script type="text/javascript" src="[!--news.url--]skin/default/js/addBuyCar.js"></script>
<script type="text/javascript">
var newsurl=&#39;<?=$public_r[newsurl]?>&#39;;
</script>

2. Modify the mall content template and add the shopping cart part to the following code:

The code is as follows:

<a href="#ecms" onclick="AddProduct([!--classid--],[!--id--]);">加入购物车</a>

Recommended study " Empire cms tutorial

3. As for the jquery file, it is compatible with versions 1.3 and 1.4 and can be downloaded by yourself. The source code of the file addBuyCar.js is as follows:

The code is as follows:

function AddProduct(classid,id) {
$.ajax({
type: "post",
url: newsurl+"e/template/ShopSys/addBuyCar.php",
data:"classid="+classid+"&id="+id,
dataType: "json",
success: function (json) {
alert(json.msg);
}
})
}

Fourth, add the handler e/template/ShopSys/addBuyCar.php, its source code is as follows:

The code is as follows:

<?php
require("../../class/connect.php");
require("../../class/db_sql.php");
require("../../data/dbcache/class.php");
require("../../class/ShopSysFun.php");
$link=db_connect();
$empire=new mysqlquery();</p> <p>//$_POST
$classid=(int)$_POST[&#39;classid&#39;];
$id=(int)$_POST[&#39;id&#39;];</p> <p>//add function
function json_AddBuycar($classid,$id){
global $class_r,$empire,$dbtbpre,$public_r;
$classid=(int)$classid;
$id=(int)$id;
if(empty($classid)||empty($id)||empty($class_r[$classid][tbname]))
{
return json_encode(array(&#39;msgid&#39;=>1,&#39;msg&#39;=>&#39;此商品不存在&#39;));
}
//验证产品是否存在
$num=$empire->gettotal("select count(*) as total from {$dbtbpre}ecms_".$class_r[$classid][tbname]." where 
classid=&#39;$classid&#39; and id=&#39;$id&#39; limit 1");
if(!$num)
{
return json_encode(array(&#39;msgid&#39;=>1,&#39;msg&#39;=>&#39;此商品不存在&#39;));
}
$record="!";
$field="|";
$productid=$classid.",".$id;
$buycar=getcvar(&#39;mybuycar&#39;);
//重复
if(strstr($buycar,"|".$productid."|"))
{
$pr=explode("|".$productid."|",$buycar);
$pr1=explode("!",$pr[1]);
$oldbuycar="|".$productid."|".$pr1[0]."!";
//数量
$pr1[0]=ReturnBuycarProductNum($pr1[0]);
if(empty($pr1[0]))
{
$pr1[0]=1;
}
$newnum=$pr1[0]+1;
$newbuycar="|".$productid."|".$newnum."!";
$buycar=str_replace($oldbuycar,$newbuycar,$buycar);
}
else
{
//只存放一个
if($public_r[&#39;buycarnum&#39;]==1)
{
$buycar=&#39;&#39;;
}
$buycar.="|".$productid."|1!";
}
$re=SetBuycar($buycar);
if($re)
{
return json_encode(array(&#39;msgid&#39;=>2,&#39;msg&#39;=>&#39;商品加入购物车成功&#39;));
}
}
echo json_AddBuycar($classid,$id);
db_close();
$empire=null;
?>

Now, the problem is solved!

The above is the detailed content of One trick to solve the problem of Imperial ECMS's method of adding AJAX to the shopping cart without refreshing. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:www.word666.com. If there is any infringement, please contact admin@php.cn delete

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.