The type of data sent to Ajax in PHP is a bit confusing with JSON

Source: Internet
Author: User
The type of data returned to Ajax in PHP is a bit confusing for JSON
This post was last edited by u013037779 on 2014-12-06 07:18:06

I am just about json_encode () How to use it is not good
For example, this is the JSON data to be transmitted in the Controller.

If I write Json_encode directly ($a);
This way, the receiving end to row here old error
I tried to use Window.alert (), to prove that the server had returned the data, but that the data was a series of HTML code that didn't know where it came from, not the data I wanted.

Ask how this should be written in Json_encode ();
In addition, if you are returning a 2-dimensional array from the database, how do I write it? For example, I queried some of his column values from the database by name.
I've encapsulated these values into 2-dimensional arrays. How can I be affected by using Json_encode to provide code
------to solve the idea----------------------
From the usage of row.city.length.
Your PHP program should only output {"City": ["Tianjin", "Wuhan", "Changsha", "Guangzhou"]} such content, if more things, it can not be converted to JS object

$a = Array ("Tianjin", "Wuhan", "Changsha", "Guangzhou");
echo json_encode (Array (' city ' = $a));

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