JQuery introduces the json format data to the background, and jquery imports the json format in the background.

Source: Internet
Author: User

JQuery introduces the json format data to the background, and jquery imports the json format in the background.

This document describes how jQuery transfers json data to the background. Share it with you for your reference. The specific analysis is as follows:

Data Interaction between the front and back ends is generally in json format. The backend can directly convert the corresponding json to an object. This facilitates future operations. When jQuery transmits data to the background, we will find that it will be automatically converted into a query string and cannot actually input a json. In addition, when jquery is used for form serialization, the returned format is an array and further conversion is required. In fact, you only need to configure something in the ajax method. The Code is as follows:

<form id="ff">   <input type="text" name="test1"/>   <input type="text" name="test2"/>   <input type="text" name="test3"/>   <input type="text" name="test4"/>   <input type="button" id="save" value="save"/> </form> $("#save").on("click", function () {  var params = $("#ff").serializeArray();  var j = {};  for (var item in params) {    j[params[item].name] = params[item].value;  }  $.ajax({    url:'index.html',    data:JSON.stringify(j),    type:'post',    dataType:'json',    headers:{  Accept:"application/json",  "Content-Type":"application/json"    },    processData:false,    cache:false  }).done(function (data) {  }); }); 

If you see the display format in chrome, it indicates the json format is passed into the background.

I hope this article will help you with jQuery programming.

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.