


Using Ajax and json to implement data interaction example of JD shopping cart settlement interface (graphic tutorial)
This article mainly introduces the data interaction example of using Ajax and json to realize the Jingdong shopping cart settlement interface. It is very good and has reference value. Friends in need can refer to it
<p class="goodsList_menu"> <p class="goodsList"> <p class="goodsListfl"> <input class="fl" style="margin:15px 10px 0 10px;" type="checkbox" name="" /> <ul> <li>全选</li> <li>商品</li> </ul> </p> <p class="goodsListfr fr"> <ul> <li>单价</li> <li class="w100">数量</li> <li class="w100">小计</li> <li>操作</li> </ul> </p> </p> <!--内容--> <p class='goodsListbox'></p> <p class="checkout"> <p class="checkoutleft"> <input class="fl" style="margin:21px 10px 0 10px;" type="checkbox" name="" /> <ul> <li>全选</li> <li>删除选中产品</li> </ul> </p> <p class="checkoutright fr"> <span>总价:<b>¥</b></span><span class="checkoutSum">0</span> <input type="button" value="去结算" /> </p> </p> </p>
body,html,ul,li,a{ margin:0;padding:0;font-family:"microsoft yahei";list-style:none;text-decoration:none; } .fl{ float:left; } .fr{ float:right; } .f12{ font-size:12px; } .disl{ display:inline-block; } .w100{ width:100px; } .fw{ font-weight:bold; } .goodsList_menu{ width:990px;height:45px;background:#f3f3f3;margin:0 auto;line-height:45px; font-size:14px;color:#333;border:1px solid #ddd; } .goodsList_menu .goodsListfl ul li{ float:left;margin-right:80px;cursor:pointer; } .goodsList_menu .goodsListfr ul li{ float:left;margin-right:37px;text-align:center;cursor:pointer; } /*内容*/ .goodsList_content{ width:100%;height:80px;border-bottom:1px solid #eee;padding:20px 0;margin-top:40px; } .goodsList_content .disl{ line-height:20px;width:300px;cursor:pointer;margin-left:10px; } .goodsList_content .disl span:hover{ color:#e4393c; } .goodsList_content .disl p:hover{ color:#e4393c; } .goodsListnum .listNum{ widows:45px;height:21px;width:50px;border:1px solid #eee;text-align:center; outline:none; } .goodsListnum ul li{ float:left;margin-right:30px;text-align:center;cursor:pointer; } .goodsListnum ul li a{ border:1px solid #ddd;padding:2px 7px;color:#000; } .goodsListnum ul li p{ line-height:0;color:#666;font-size:12px;margin-top:-2px; } .buy_goods p{ background:url(../images/arrow.png)no-repeat;padding-left:30px;background-position:-20px -20px; } .buy_goods{ position:relative; } /*底部结账*/ .checkout{ height:55px;border:1px solid #eee;margin-top:20px;line-height:55px; } .checkout .checkoutleft ul li{ float:left;margin-right:10px;cursor:pointer; } .checkout .checkoutSum{ font-weight:bold;font-size:18px;color:#e64346; } .checkout .checkoutright input{ border:none;color:#fff;outline:none;width:100px;height:55px;line-height:55px; font-size:20px;background:#e64346;margin-left:50px;cursor:pointer; }
<script> $.ajax({ type:"get", url:"jd.json", dataType:"json", success:function(data){ var list = data.list;//拿到list数组 //console.log(list); for(var i=0;i<list.length;i++){ var numArray = list[i]; numArray.price = (numArray.price).toFixed(2); var text = "<p class='goodsList_content'><p class='fl buy_goods'>"+ "<input class='fl' style='margin:15px 10px 0 10px;' type='checkbox' name='' />"+ "<img align='top' src='images/1.jpg' / alt="Using Ajax and json to implement data interaction example of JD shopping cart settlement interface (graphic tutorial)" ><p class='disl'>"+ "<span>"+numArray.description+"</span><p class='f12'>购买礼品服务</p></p>"+ "<p class='disl' style='width:auto;position:absolute;right:-100px;top:0;'>"+ "<span>"+numArray.color+"</span></p></p>"+ "<p class='fr goodsListnum' style='margin-top:-12px;'>"+ "<ul><li><b>¥</b><span class='fw'>"+numArray.price+"</span></li>"+ "<li class='w100'><a class='minus' onClick='minus(this);' href='javascript:void(0);'>-</a>"+ "<input value='1' class='listNum' /><a class='add' onClick='add(this)' href='javascript:void(0);'>+</a><p>有货</p></li>"+ "<li class='w100'><b>¥</b><span id='sub' class='fw'>"+numArray.price*numArray.quentity+"</span></li>"+ "<li><a style='border:none;color:#666;' href='javascript:void(0);'>删除</a></li>"+ "</ul></p></p>" $(text).appendTo(".goodsListbox"); } }, error:function(){ console.log("调用数据失败!"); } }); var listNum,price,sums,sub1,sub2; function add(obj){ listNum = $(obj).prev().val();//input值 listNum = parseInt(listNum); var num = parseInt(listNum+1);//input值每次+1 $(obj).prev().val(num); price = $(obj).parent().prev().children('span').text();//找到单价 price = parseInt(price);//转换成number类型 price = price.toFixed(2); sums = $(obj).parent().next().children('span').text()//找到总金额 sums = parseInt(sums); console.log(typeof sums); $(obj).parent().next().children('span').text(price*num); sub1 = $(".goodsList_content:eq(0)").find("#sub").text(); sub2 = $(".goodsList_content:eq(1)").find("#sub").text(); sub1 = parseInt(sub1); sub2 = parseInt(sub2); var res = $(".checkoutright .checkoutSum").text((sub1+sub2).toFixed(2)); } function minus(obj){ listNum = $(obj).next().val(); listNum = parseInt(listNum); if(listNum<=1){ listNum==1; }else{ --listNum; } $(obj).next().val(listNum); price = $(obj).parent().prev().children('span').text();//找到单价 price = parseInt(price);//转换成number类型 price = price.toFixed(2); sums = $(obj).parent().next().children('span').text()//找到总金额 sums = parseInt(sums); $(obj).parent().next().children('span').text(price*listNum); $(".checkoutright .checkoutSum").text(price*listNum); sub1 = $(".goodsList_content:eq(0)").find("#sub").text(); sub2 = $(".goodsList_content:eq(1)").find("#sub").text(); sub1 = parseInt(sub1); sub2 = parseInt(sub2); $(".checkoutright .checkoutSum").text(sub1+sub2); } </script>
The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.
Related articles:
Implementing WebApi Ajax cross-domain request solution based on CORS
ajax front-end and back-end cross-domain request processing method (Figure Text tutorial)
Native JS implements Ajax cross-domain request flask response content (graphic tutorial)
The above is the detailed content of Using Ajax and json to implement data interaction example of JD shopping cart settlement interface (graphic tutorial). For more information, please follow other related articles on the PHP Chinese website!

The main uses of JavaScript in web development include client interaction, form verification and asynchronous communication. 1) Dynamic content update and user interaction through DOM operations; 2) Client verification is carried out before the user submits data to improve the user experience; 3) Refreshless communication with the server is achieved through AJAX technology.

Understanding how JavaScript engine works internally is important to developers because it helps write more efficient code and understand performance bottlenecks and optimization strategies. 1) The engine's workflow includes three stages: parsing, compiling and execution; 2) During the execution process, the engine will perform dynamic optimization, such as inline cache and hidden classes; 3) Best practices include avoiding global variables, optimizing loops, using const and lets, and avoiding excessive use of closures.

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

JavaScript's applications in the real world include server-side programming, mobile application development and Internet of Things control: 1. Server-side programming is realized through Node.js, suitable for high concurrent request processing. 2. Mobile application development is carried out through ReactNative and supports cross-platform deployment. 3. Used for IoT device control through Johnny-Five library, suitable for hardware interaction.

I built a functional multi-tenant SaaS application (an EdTech app) with your everyday tech tool and you can do the same. First, what’s a multi-tenant SaaS application? Multi-tenant SaaS applications let you serve multiple customers from a sing


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver CS6
Visual web development tools

Atom editor mac version download
The most popular open source editor

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 Mac version
God-level code editing software (SublimeText3)

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