The difference between Text/javascript and Application/json __javascript

Source: Internet
Author: User

When the server returns JSON-formatted data to the browser end, the following code is used:

Response.setcontenttype ("Text/javascript;charset=utf-8");

Response.setcontenttype ("Application/json;charset=utf-8");

Difference:

Text/javascript is used to return the JS code, Application/json specifically used to return data in JSON format.

The JS code returned by the former is automatically executed in the browser, just as the result of the return is called by Eval. That is to say the returned string, will be used as JS code, the browser's JS engine to carry out. Instead of being displayed as a normal string in the browser.

The JS code returned by the former is automatically executed in the browser, just as it was called by eval (result). The code written back to the browser is processed as JS, which is specifically used to return the JSON string.

JSON-formatted data is also a JS string that is parsed by the browser as a JSON object and returns the JSON string, both of which apply.

Overall:

Server-side---->>>> clients send JSON data

Response.setcontenttype ("Text/javascript;charset=utf-8");

Response.setcontenttype ("Application/json;charset=utf-8");

Client sends JSON data----->>>> Server:

 content-type = ' application/json;charset=utf-8 '  
 content-type = ' Text/json;charset=utf-8 '  
 content-type = ' text/javascript;charset=utf-8 '  
 content-type = ' application/ Javascript;charset=utf-8 '  

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.