Ajax returns a Data Group to process the data group.

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.