For Ajax response, there is no method to directly return data sets, so I just thought of a simple method. If there is a better method, hope to leave some points.
1. on the server side (PHP), we can use the following to export data. Here I use the data records of the two fields.
$ Id = $ _ Get ['id'];
$ Cate = $ db-> getall ("select ID, name from product_category where parentid =". $ id );
Foreach ($ cate as $ key => $ I ){
Echo $ I ['id']. ",". $ I ['name']. "| ";
}
2. In JS runtime, I use the get method.
VaR STR = XMLHTTP. responsetext;
Incate = Str. Split ("| ");
For (VAR I = 0; I <incate. Length/2; I ++ ){
VaR eloptnew = Document. createelement ('option ');
VaR T = new array ();
T = incate [I]. Split (",");
Eloptnew. Text = T [1];
Eloptnew. value = T [0];
Sel. Add (eloptnew );
}
In this case, the Select menu of zookeeper is separated by two JS split methods to cut the string.