search
HomeWeb Front-endJS TutorialDetailed explanation of jQuery+ajax reading json and sorting method

This time I will bring you jQuery A detailed explanation of the ajax method of reading json and sorting. What are the precautions for jQuery ajax to read json and sorting? The following is a practical case, one Get up and take a look.

nbsp;html>


 <meta>
 <title></title>
 <script></script>
 <script>
 $.ajax({
  url: &#39;data.json&#39;,//获取本地json数据,在同文件夹下
  type: "get",
  success: function(resp) {
  console.log(resp); //原始数据
  var data = resp;
  //原生javascript sort() 方法
  data.data.sort(function(good1, good2) {
   /* 用价格排序由小到大 */
   return good1.price1 > good2.price1;
  });
  console.log(data.data);//排序后的数据
  },
  error: function(resp) {
  alert("系统繁忙,请稍后再试...");
  }
 });
 </script>



json data data.json:

{
 "code": 0,
 "data": [{
  "id": 16,
  "title": "fiveplus棉质纯色拼接圆领连衣裙",
  "name": "FivePlus2017新品女夏装棉质纯色拼接圆领短袖连衣裙2JM2080240",
  "promotion": "促销活动",
  "size": "XXl;Xl;M;S;L",
  "color": "深蓝;深绿",
  "picMini": "",
  "pic": "/upload/20170826161653_20170823141557.jpg,/upload/20170826161653_20170823141625.jpg,/upload/20170826161653_20170823141803.jpg,/upload/20170826161653_20170823141857.jpg,/upload/20170826161653_20170823141925.jpg",
  "parameter": "材质成分:棉68%聚酯纤维29.5%聚氨酯弹性纤维(氨纶)2.5%;销售渠道类型:商场同款(线上线下都销售);货号:2JM2080240;裙长:短裙;品牌:FivePlus;适用年龄:25-29周岁;年份季节:2017年夏季;颜色分类:深蓝650米白010;尺码:X、S、M、L",
  "businessName": "北京房益宝",
  "typeName": "连衣裙",
  "businessId": 1,
  "status": 1,
  "typeId": 8,
  "brandId": null,
  "price1": 399.00,
  "price2": 799.00,
  "longPic": "/upload/20170828102154_haibao (1).png",
  "score": 20,
  "createDate": "2017-08-26 14:49:09",
  "updateDate": "2017-08-26 14:49:09"
 }, {
  "id": 18,
  "title": "MOCO高腰拼接无袖镂空蕾丝连衣裙",
  "name": "MOCO高腰拼接无袖镂空蕾丝连衣裙修身A字裙子MA162SKT106摩安珂",
  "promotion": null,
  "size": "S;M",
  "color": "白色;黑色",
  "picMini": "",
  "pic": "/upload/20170826161938_TB1BiAdOFXXXXaYXXXXXXXXXXXX_!!0-item_pic.jpg_430x430q90.jpg,/upload/20170826161938_TB2PwEAa30kpuFjSspdXXX4YXXa_!!1746622942.jpg_430x430q90.jpg,/upload/20170826161938_TB2uqPaaStkpuFjy0FhXXXQzFXa_!!1746622942.jpg_430x430q90.jpg,/upload/20170826161938_TB2ZW4HcR0kpuFjSsziXXa.oVXa_!!1746622942.jpg_430x430q90.jpg,/upload/20170826161938_TB22u2TaC0mpuFjSZPiXXbssVXa_!!1746622942.jpg_430x430q90.jpg",
  "parameter": "廓形:A型;材质成分:聚酯纤维94.4%聚氨酯弹性纤维(氨纶)5.6%;销售渠道类型:商场同款(线上线下都销售);货号:MA162SKT106;风格:街头;街头:欧美组合;形式:单件;裙长:短裙;款式:其他/other;袖长:无袖;领型:圆领;袖型:常规;腰型:高腰衣;门襟:拉链;裙型:A字裙;图案:花色;流行元素/工艺:镂空勾花镂空蕾丝;品牌:Mo&Co./摩安珂;适用年龄:25-29周岁;年份季节:2016年夏季",
  "businessName": "北京房益宝",
  "typeName": "连衣裙",
  "businessId": 1,
  "status": 1,
  "typeId": 8,
  "brandId": null,
  "price1": 300.00,
  "price2": 400.00,
  "longPic": null,
  "score": 20,
  "createDate": "2017-08-26 15:10:48",
  "updateDate": "2017-08-26 15:10:48"
 }, {
  "id": 20,
  "title": "CMissSixty夏装拼接露肩式牛仔连衣裙",
  "name": "CMissSixty夏装拼接露肩式牛仔连衣裙套装662DJ3220000",
  "promotion": null,
  "size": "XSML",
  "color": "深蓝;红色;白色",
  "picMini": "",
  "pic": "/upload/20170826162219_TB1F80hQXXXXXc8XXXXXXXXXXXX_!!0-item_pic.jpg_430x430q90.jpg,/upload/20170826162219_TB2jpAydDcCL1FjSZFPXXXZgpXa_!!1880906465.jpg_430x430q90.jpg,/upload/20170826162219_TB2NnpRi5pnpuFjSZFkXXc4ZpXa_!!1880906465.jpg_430x430q90.jpg,/upload/20170826162219_TB2UB4Wi98mpuFjSZFMXXaxpVXa_!!1880906465.jpg_430x430q90.jpg,/upload/20170826162219_TB2zhxMi.hnpuFjSZFEXXX0PFXa_!!1880906465.jpg_430x430q90.jpg",
  "parameter": "材质成分:棉98.4%聚氨酯弹性纤维(氨纶)1.6%;销售渠道类型:商场同款(线上线下都销售);货号:662DJ3220000;裙长:中裙;品牌:Misssixty;适用年龄:25-29周岁;年份季节:2016年夏季;颜色分类:深蓝F58;尺码:XS、S、M、L",
  "businessName": "测试111",
  "typeName": "连衣裙",
  "businessId": 3,
  "status": 1,
  "typeId": 8,
  "brandId": null,
  "price1": 800.00,
  "price2": 1000.00,
  "longPic": "",
  "score": 30,
  "createDate": "2017-08-26 16:21:49",
  "updateDate": "2017-08-26 16:21:49"
 }, {
  "id": 45,
  "title": "雪纺连衣裙2017新款秋装七分袖气质时尚女装碎花修身连衣裙春秋",
  "name": "气质女神,春秋必备",
  "promotion": null,
  "size": "SMLXL",
  "color": "白色;粉色;兰色;黑色",
  "picMini": "",
  "pic": "/upload/20170828111058_TB1vZ7MQFXXXXaLXVXXXXXXXXXX_!!0-item_pic.jpg_430x430q90.jpg,/upload/20170828111058_TB2Dtj2hw0kpuFjSspdXXX4YXXa_!!729863055.jpg_430x430q90.jpg,/upload/20170828111058_TB2off_hB0kpuFjSsziXXa.oVXa_!!729863055.jpg_430x430q90.jpg,/upload/20170828111058_TB2pOW1hylnpuFjSZFgXXbi7FXa_!!729863055.jpg_430x430q90.jpg,/upload/20170828111058_TB2SRuLgmxjpuFjSszeXXaeMVXa_!!729863055.jpg_430x430q90.jpg",
  "parameter": "廓形:A型;材质成分:其他100%;销售渠道类型:纯电商(只在线上销售);货号:AF5130;风格:通勤;通勤:韩版组合形式:单件;裙长:中裙;款式:其他/other;袖长:七分袖;领型:圆领;袖型:常规;腰型:中腰;衣门襟:拉链;裙型:A字裙;图案:花色;流行元素/工艺:绣花拼接螺纹拉链;品牌:芳香之城;面料:雪纺;适用年龄:25-29周岁;年份季节:2017年夏季;颜色分类:白色、粉色、兰色、黑色;尺码:S、M、L、XL",
  "businessName": "北京房益宝",
  "typeName": "连衣裙",
  "businessId": 1,
  "status": 1,
  "typeId": 8,
  "brandId": null,
  "price1": 139.00,
  "price2": 259.00,
  "longPic": "",
  "score": 13,
  "createDate": "2017-08-28 11:10:41",
  "updateDate": "2017-08-28 11:10:41"
 }, {
  "id": 46,
  "title": "韩版女装2017夏季新款冰丝针织小黑裙连衣裙中裙女夏装露肩a字裙",
  "name": "新款冰丝针织小黑裙",
  "promotion": null,
  "size": "SMLXL",
  "color": "黑色",
  "picMini": "",
  "pic": "/upload/20170828111250_TB1pFJsPFXXXXbUXVXXXXXXXXXX_!!0-item_pic.jpg_430x430q90.jpg,/upload/20170828111250_TB2aHefXxRDOuFjSZFzXXcIipXa_!!2923124116.jpg_430x430q90.jpg,/upload/20170828111250_TB2CBbAeB0kpuFjSsziXXa.oVXa_!!2923124116.jpg_430x430q90.jpg,/upload/20170828111250_TB2wbcahCJjpuFjy0FdXXXmoFXa_!!2923124116.jpg_430x430q90.jpg,/upload/20170828111250_TB21GzPeB8lpuFjSspaXXXJKpXa_!!2923124116.jpg_430x430q90.jpg",
  "parameter": "廓形:A型;材质成分:其他100%;销售渠道类型:纯电商(只在线上销售);货号:AF5130;风格:通勤;通勤:韩版组合形式:单件;裙长:中裙;款式:其他/other;袖长:七分袖;领型:圆领;袖型:常规;腰型:中腰;衣门襟:拉链;裙型:A字裙;图案:花色;流行元素/工艺:绣花拼接螺纹拉链;品牌:芳香之城;面料:雪纺;适用年龄:25-29周岁;年份季节:2017年夏季;颜色分类:白色、粉色、兰色、黑色;尺码:S、M、L、XL",
  "businessName": "北京房益宝",
  "typeName": "连衣裙",
  "businessId": 1,
  "status": 1,
  "typeId": 8,
  "brandId": null,
  "price1": 158.00,
  "price2": 188.00,
  "longPic": "",
  "score": 15,
  "createDate": "2017-08-28 11:15:09",
  "updateDate": "2017-08-28 11:15:09"
 }, {
  "id": 47,
  "title": "吊带露背沙滩裙女夏2017新款海边度假性感波西米亚长裙显瘦连衣裙",
  "name": "吊带露背沙滩裙",
  "promotion": null,
  "size": "LSM",
  "color": "094花俏",
  "picMini": "",
  "pic": "/upload/20170828111644_TB1CbX8RVXXXXaqXVXXXXXXXXXX_!!0-item_pic.jpg_430x430q90.jpg,/upload/20170828111644_TB2e5Yfp0RopuFjSZFtXXcanpXa_!!1969979810.jpg_430x430q90.jpg,/upload/20170828111644_TB2Q0ZZvNXkpuFjy0FiXXbUfFXa_!!1969979810.jpg_430x430q90.jpg,/upload/20170828111644_TB2qXsqvSBjpuFjSsplXXa5MVXa_!!1969979810.jpg_430x430q90.jpg,/upload/20170828111644_TB2twgOkutTMeFjSZFOXXaTiVXa_!!1969979810.jpg_430x430q90.jpg",
  "parameter": "廓形:A型;材质成分:其他100%;销售渠道类型:纯电商(只在线上销售);货号:AF5130;风格:通勤;通勤:韩版组合形式:单件;裙长:中裙;款式:其他/other;袖长:七分袖;领型:圆领;袖型:常规;腰型:中腰;衣门襟:拉链;裙型:A字裙;图案:花色;流行元素/工艺:绣花拼接螺纹拉链;品牌:芳香之城;面料:雪纺;适用年龄:25-29周岁;年份季节:2017年夏季;颜色分类:白色、粉色、兰色、黑色;尺码:S、M、L、XL",
  "businessName": "北京房益宝",
  "typeName": "连衣裙",
  "businessId": 1,
  "status": 1,
  "typeId": 8,
  "brandId": null,
  "price1": 148.00,
  "price2": 248.00,
  "longPic": "",
  "score": 14,
  "createDate": "2017-08-28 11:17:44",
  "updateDate": "2017-08-28 11:17:44"
 }, {
  "id": 49,
  "title": "Palglg裙子女2017新款夏季女装韩版宽松挂脖a字网纱连衣裙3353",
  "name": "精致绣花宽松显瘦减龄蝴蝶结系带",
  "promotion": null,
  "size": "SML",
  "color": "藕粉色;白色;浅绿色",
  "picMini": "",
  "pic": "/upload/20170828111920_TB1HTyLX0.LL1JjSZFEXXcVmXXa_!!0-item_pic.jpg_430x430q90.jpg,/upload/20170828111920_TB2BAcZubVkpuFjSspcXXbSMVXa_!!2456840063.jpg_430x430q90.jpg,/upload/20170828111920_TB2cnK7gH0kpuFjy0FjXXcBbVXa_!!2456840063.jpg_430x430q90.jpg,/upload/20170828111920_TB2rm4utMxlpuFjy0FoXXa.lXXa_!!2456840063.jpg_430x430q90.jpg,/upload/20170828111920_TB2xLw0hYxmpuFjSZJiXXXauVXa_!!2456840063.jpg_430x430q90.jpg",
  "parameter": "廓形:A型;材质成分:其他100%;销售渠道类型:纯电商(只在线上销售);货号:AF5130;风格:通勤;通勤:韩版组合形式:单件;裙长:中裙;款式:其他/other;袖长:七分袖;领型:圆领;袖型:常规;腰型:中腰;衣门襟:拉链;裙型:A字裙;图案:花色;流行元素/工艺:绣花拼接螺纹拉链;品牌:芳香之城;面料:雪纺;适用年龄:25-29周岁;年份季节:2017年夏季;颜色分类:白色、粉色、兰色、黑色;尺码:S、M、L、XL",
  "businessName": "北京房益宝",
  "typeName": "连衣裙",
  "businessId": 1,
  "status": 1,
  "typeId": 8,
  "brandId": null,
  "price1": 169.00,
  "price2": 369.00,
  "longPic": "",
  "score": 16,
  "createDate": "2017-08-28 11:20:06",
  "updateDate": "2017-08-28 11:20:06"
 }, {
  "id": 50,
  "title": "拉夏贝尔2017夏季新款bf风韩版气质潮裙子学生衬衫式连衣裙衣女",
  "name": "bf风韩版气质潮裙子",
  "promotion": null,
  "size": "SML",
  "color": "粉红;白色;浅蓝",
  "picMini": "",
  "pic": "/upload/20170828112125_TB1J2CUXo4WMKJjSspmXXcznpXa_!!0-item_pic.jpg_430x430q90.jpg,/upload/20170828112125_TB2K_FOiYXlpuFjSszfXXcSGXXa_!!2146742267.jpg_430x430q90.jpg,/upload/20170828112125_TB2nL6ht3JkpuFjSszcXXXfsFXa_!!2146742267.jpg_430x430q90.jpg,/upload/20170828112125_TB2Skz0dlU4h1JjSZFLXXaFMpXa_!!2146742267.jpg_430x430q90.jpg,/upload/20170828112125_TB2WEVJi9hlpuFjSspkXXa1ApXa_!!2146742267.jpg_430x430q90.jpg",
  "parameter": "廓形:A型;材质成分:其他100%;销售渠道类型:纯电商(只在线上销售);货号:AF5130;风格:通勤;通勤:韩版组合形式:单件;裙长:中裙;款式:其他/other;袖长:七分袖;领型:圆领;袖型:常规;腰型:中腰;衣门襟:拉链;裙型:A字裙;图案:花色;流行元素/工艺:绣花拼接螺纹拉链;品牌:芳香之城;面料:雪纺;适用年龄:25-29周岁;年份季节:2017年夏季;颜色分类:白色、粉色、兰色、黑色;尺码:S、M、L、XL",
  "businessName": "北京房益宝",
  "typeName": "连衣裙",
  "businessId": 1,
  "status": 1,
  "typeId": 8,
  "brandId": null,
  "price1": 199.00,
  "price2": 399.00,
  "longPic": "",
  "score": 19,
  "createDate": "2017-08-28 11:21:49",
  "updateDate": "2017-08-28 11:21:49"
 }
 ]
}

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

What steps are needed to get ModelAndView in js

Add ellipses when the text exceeds the specified number of lines

How to determine if el expression is not empty

The above is the detailed content of Detailed explanation of jQuery+ajax reading json and sorting method. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
From Websites to Apps: The Diverse Applications of JavaScriptFrom Websites to Apps: The Diverse Applications of JavaScriptApr 22, 2025 am 12:02 AM

JavaScript is widely used in websites, mobile applications, desktop applications and server-side programming. 1) In website development, JavaScript operates DOM together with HTML and CSS to achieve dynamic effects and supports frameworks such as jQuery and React. 2) Through ReactNative and Ionic, JavaScript is used to develop cross-platform mobile applications. 3) The Electron framework enables JavaScript to build desktop applications. 4) Node.js allows JavaScript to run on the server side and supports high concurrent requests.

Python vs. JavaScript: Use Cases and Applications ComparedPython vs. JavaScript: Use Cases and Applications ComparedApr 21, 2025 am 12:01 AM

Python is more suitable for data science and automation, while JavaScript is more suitable for front-end and full-stack development. 1. Python performs well in data science and machine learning, using libraries such as NumPy and Pandas for data processing and modeling. 2. Python is concise and efficient in automation and scripting. 3. JavaScript is indispensable in front-end development and is used to build dynamic web pages and single-page applications. 4. JavaScript plays a role in back-end development through Node.js and supports full-stack development.

The Role of C/C   in JavaScript Interpreters and CompilersThe Role of C/C in JavaScript Interpreters and CompilersApr 20, 2025 am 12:01 AM

C and C play a vital role in the JavaScript engine, mainly used to implement interpreters and JIT compilers. 1) C is used to parse JavaScript source code and generate an abstract syntax tree. 2) C is responsible for generating and executing bytecode. 3) C implements the JIT compiler, optimizes and compiles hot-spot code at runtime, and significantly improves the execution efficiency of JavaScript.

JavaScript in Action: Real-World Examples and ProjectsJavaScript in Action: Real-World Examples and ProjectsApr 19, 2025 am 12:13 AM

JavaScript's application in the real world includes front-end and back-end development. 1) Display front-end applications by building a TODO list application, involving DOM operations and event processing. 2) Build RESTfulAPI through Node.js and Express to demonstrate back-end applications.

JavaScript and the Web: Core Functionality and Use CasesJavaScript and the Web: Core Functionality and Use CasesApr 18, 2025 am 12:19 AM

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 the JavaScript Engine: Implementation DetailsUnderstanding the JavaScript Engine: Implementation DetailsApr 17, 2025 am 12:05 AM

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 vs. JavaScript: The Learning Curve and Ease of UsePython vs. JavaScript: The Learning Curve and Ease of UseApr 16, 2025 am 12:12 AM

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 vs. JavaScript: Community, Libraries, and ResourcesPython vs. JavaScript: Community, Libraries, and ResourcesApr 15, 2025 am 12:16 AM

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.

See all articles

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot 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.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools