Data returned by thinkphpajaxreturn

Source: Internet
Author: User
Thinkphpajaxreturn returns data problems thinkphp is really not easy to use, there is always a problem, why thinkphp ajaxreturn returns a json string, not a json object. Local is the returned object, the server is the returned string, solve ......


Reply to discussion (solution)


No one cares ......

Json string? What is the concept?

Json string? What is the concept?



Data generated locally using alert


On the server, What alert comes out is

It should be something that can be controlled.

I have never used this framework, eva or JSON. parse.

It should be something that can be controlled.

I have never used this framework, eva or JSON. parse.



I know this, but why is it different between the local server and the server? is it a server configuration problem? it is impossible to use two sets of code locally and on the server?


It should be something that can be controlled.

I have never used this framework, eva or JSON. parse.



I know this, but why is it different between the local server and the server? is it a server configuration problem? it is impossible to use two sets of code locally and on the server?



The server configuration does not matter. does thinkphp have this configuration?

LZ. It is recommended that you go to the official THINKPHP forum for more efficient consultation...

DataType: 'json'

DataType: 'json'



He knows this.

Before you convert it to json, you can view the output result set.

Http transmits all text. why object?
Json itself is a data representation in text format. it is changed to js object only after interpretation and execution by the js engine.

Your #3 json data string has been correctly returned
So why is the string not converted into an object?
This is related to the default return header of your server, and of course also to the browser you are using.
You can output headers that declare the json data type before return.
You can also determine whether to perform another conversion by determining the data type in js.
Of course, the above discussion is based on the fact that your program has not changed.

In addition, thinkphp cannot be blamed, because thinkphp cannot predict which browsers will be less humane. it is rigid to interpret data according to the http header.

In conclusion, the Post is closed,

The first possible problem is: json returned objects encapsulated by thinkphp are not supported by some browsers, so this method is not required.
The second problem is: our colleagues in the company use different development environments and different systems. some files generate bom problems, resulting in more spaces in the ajax return values.

I also have multiple spaces, causing 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.