Ajax Examples (2)

Source: Internet
Author: User

When it comes to Ajax, of course, JSON format. In the process of data transmission of Ajax, the most used is the JSON format.

What is the JSON format, at the beginning of the use of it, it really makes people confused for a while. That's a little white. So-called JSON is not a form of data.

As long as we understand this format, we can use Ajax to facilitate the transfer of data. When it comes to JSON format, we also talk about objects and arrays in JS. So knowledge is all about each other.

Contact, the mastery of knowledge is still very important.

The JSON syntax is a subset of the JavaScript object representation syntax. Although JSON is simply the object and array in JS. But using Ajax to pass the JSON format to the background

The data is still going to be converted. Otherwise, the data cannot be successfully obtained in the background.

Front desk JS Code

var daytimeobj={};//declaring a JS objectvar daytime=[1,2,3,4];//declaring a JS arrayDaytimeobj.rows=daytime;//Properties$.ajax ({URL:"Insertdata.do", type:"POST", DataType:"JSON", data:{"Daytimeobj": Json.stringify (Daytimeobj),}, Success:function (data) {if(data) {alert ("OK"); }                          });

Get JSON data in the background

Background Java code

Import Net.sf.json.JSONArray;
Import Net.sf.json.JSONObject;

Response.setcontenttype ("Text/json; Charset=utf-8 "); String daytimeobj=request.getparameter ("Daytimeobj"); Jsonobject TT=jsonobject.fromobject (daytimeobj); // encapsulate as JSON object Object a=tt.get ("Rows"); Jsonarray jsonArray2=jsonarray.fromobject (a); // encapsulate an array of objects  for (int i = 0; i < jsonarray2.size (); i++) {            // loop to get the value            of the array                                    }

Ajax Examples (2)

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.