Javaweb returning JSON-formatted data jquery ajax unresolved issues

Source: Internet
Author: User

Today, when I was writing the lab's stupid Java Web Gadget, there was a place to post content because what you wanted to do was make the user feel elegant.

So is the use of Ajax to do, originally very simple a small thing, unexpectedly spent more than half an hour of time, mainly to spend time in jquery can not return the JSON

The message data to the popup window display, this he is really enough to toss, originally thought is the back end of the setcontenttype problem, but the view on-line information is said to be

Use Application/json;charset=utf-8, this is the most standard, then why I set this is not possible, because I directly return is

The string in Java, which is directly spliced like "{' name ': ' Zjam ', ' age ': 20"} Such a string, so that caused the problem,

After searching to know that jquery more than 1.4 of the format of the JSON more stringent requirements, all the keys and attributes are marked with double quotes,

Otherwise it will be treated as a return string. What a pain, instead of "{\" name\ ": \" Zjam\ "}" after the format of the problem successfully resolved,

Really enough egg pain, it seems that in the future do not directly spell string, or use the library to solve the good.

Javaweb returning JSON-formatted data jquery ajax unresolved issues

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.