thinkphp Ajaxreturn Return Data problem

Source: Internet
Author: User
Thinkphp really use the wrong, old problems, why thinkphp Ajaxreturn returned is a JSON-formatted string, not a JSON object. Local is the return object, the server is the return string, solve ...


Reply to discussion (solution)


No-nobody ...

A string in JSON format? What's the concept?

A string in JSON format? What's the concept?



Local alert-out data


On the server, alert comes out of the

There should be a place to control it.

Don't use this frame yourself Eva or json.parse a bit

There should be a place to control it.

Don't use this frame yourself Eva or json.parse a bit



This I know, but the local and server why is not the same, is not a server configuration problem, it is not possible to use local and server two sets of code AH?


There should be a place to control it.

Don't use this frame yourself Eva or json.parse a bit



This I know, but the local and server why is not the same, is not a server configuration problem, it is not possible to use local and server two sets of code AH?



Server configuration should not have this relationship ah, thinkphp have this setting?

Lz. Suggest you go to thinkphp Official forum consultation is more efficient ...

DataType: ' JSON '

DataType: ' JSON '



He should know that.

Before you convert to JSON, look at the output result set.

HTTP is the text that transmits, what object does it come from?
JSON itself is a text format of the data representation, only through the JS engine to explain the execution will only become JS object

You #3 indicate that the JSON data string has been returned correctly.
So why is the string of figure two not being converted to an object?
This is related to the default return header of your server and, of course, to the browser you are using.
You can output the header that declares the JSON data type before returning
You can also decide whether you need to make a conversion by judging the data type in JS.
Of course, the discussion above is based on the lack of change in your program.

In addition, this can not blame thinkphp, because thinkphp can not predict which browsers will be so impersonal, rigid HTTP header to interpret the data

In conclusion, the knot has been pasted,

The first possible problem is in: thinkphp encapsulated JSON return object, some browsers do not support, so do not use the official method
The second problem is: Our company colleagues use the development environment is not the same, the system is different, some files produced a BOM problem, resulting in the Ajax return value more space

I also have multiple spaces, egg pain

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