This article mainly introduces jQuery's method of transmitting json format data to the background. The example analyzes the principle and implementation skills of transmitting json format data, which has some reference value, for more information about how jQuery transfers json data to the background, see the following example. 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:
$ ("# 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', ype: '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.