Javascript-I have read several ajax tutorials, but it may be that the tutorials are not deep enough. I would like to ask how to get the php server to return N pieces of information?

Source: Internet
Author: User
All the tutorials I read are on the server echostring... output a string and hand it to the front-end js for processing. I would like to ask how to get a search page that returns dozens of results at once? Whether to return a string, then cut it into an array, and then process it again, or php can... all the tutorials I have read are output a string on the server echo string,
And then hand it to the front-end js for processing.

I would like to ask how to get a search page that returns dozens of results at once?

Is to return a string, then cut it into an array, and then process it,

Or can php directly return an object or an array?

Reply content:

All the tutorials I have read are a string generated on the server echo string,
And then hand it to the front-end js for processing.

I would like to ask how to get a search page that returns dozens of results at once?

Is to return a string, then cut it into an array, and then process it,

Or can php directly return an object or an array?

PHPechoThe output is a string, but you can usejson_encodeIf an array is formatted as a json string, multiple messages can be returned.

$data = [];$data[] = 'data1';$data[] = 'data2';$data[] = 'data3';$data[] = 'data4';$str = json_encode($data);echo $str;exit;

The front-end obtains an array object.

Json can be an array .. For example, you don't need paging.

Returns an array. after parsing, the array can contain a lot of json. then, you can create an appropriate number of html elements based on the array length.

Return json data

ReturnjsonOrxmlFormat data, first pushjson.

Returns the json Array and then traverses it.

I personally think it is complicated to process the client webpage (android, ios, etc.). if it is too complicated, the server generates HTML responses.
Otherwise, all are returned.jsonFormat data, processed by the customer service endjson_encode($list);

Of course, returnxmlYes, but as you can seejsonIs mainstream,phpOperationjsonEasy to use

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.