Nodejs is used to obtain the product category of a certain treasure, and the product category of nodejs treasure
I have nothing to worry about. I studied e-commerce websites. My friends opened a store and saw a wide variety of products. So I did a little research.
AJAX is used to obtain the product category. Because of the need to log on to the product, I am not busy. The simplest way is to log on to the console and directly open the console and paste the code to run it. Hey, all Categories run to CAT. data.
Cainiao trainer, please advise.
Var CAT = {// [{id: '', name:'', data: [{id: '', name:'', data: [{id: '', name:''}] },{},...]}, {}...] data: [], url: function () {return 'HTTP: // upload.taobao.com/auction/json/reload_cats.htm? T = '+ Math. random () ;}, init: function () {var url = CAT. url (), post_data = 'path = all'; CAT. ajax (url, post_data, CAT. first_r) ;}, first_r: function (data) {var rs = data [0] ['data'], first_l, first_d, I, j, second_id, second_d, func; for (I = 0; I <rs. length; I ++) {// Save the first-level category first_d = rs [I] ['data']; first_l = []; for (j = 0; j <first_d.length; j ++) {// saves the second-level category and queries the third-level category, and provides the container second_id = first_d [j] ['sid ']; secon D_d = {'id': first_d [j] ['sid '], 'name': first_d [j] ['name'], 'spell ': first_d [j] ['spell '], 'data': []}; first_l.push (second_d); func = CAT. second_r (second_d ['data']); CAT. ajax (CAT. url (), 'path = next & sid = '+ second_id, func);} CAT. data. push ({'id': rs [I] ['id'], 'name': rs [I] ['name'], 'data ': first_l}) }}, second_r: function (container) {return function (data) {if (data. length <1) {return} var rs = da Ta [0] ['data'], I, j, here, third_d; for (I = 0; I <rs. length; I ++) {third_d = rs [I] ['data']; for (j = 0; j <third_d.length; j ++) {here = third_d [j]; container. push ({'id': here ['sid '], 'name': here ['name'], 'spell ': here ['spell ']}) ;}}}, ajax: function (url, post_data, func) {var xhr = new XMLHttpRequest (), result; xhr. open ('post', url, true); xhr. setRequestHeader ("Content-type", "application/x-www- M-urlencoded "); xhr. send (post_data); xhr. onreadystatechange = function () {if (xhr. readyState = 4 & xhr. status = 200) {result = JSON. parse (xhr. responseText); func (result);} else if (xhr. readyState = 4 &&(! Xhr. status = 200) {console. log ('ajax Return Error! ') ;}}}; CAT. init ();
The above is all the content of this article. I hope you will like it.