How to process requests for JSON data with ajax encapsulated by jQuery
Editor to share with you jQuery encapsulated ajax how to process requests for JSON data, I believe most people do not know much about it, so share this article for your reference, I hope you will learn a lot after reading this article, let's go to know it!
The specific implementation code is as follows:
JavaScript code
{"data": [{"id": "1", "name": "Select A", "value": "A"}, {"id": "2", "name": "Select B", "value": "B"}, {"id": "3", "name": "Select C", "value": "C"}]}
Parse the above json data class in the success function of jquery
JavaScript code
Ajax ({type: "POST", url: "xxx.do", dataType: "json", / / specify the return type data: {xxx: "yyy"}, / / the parameter success passed to the background: function (data) {$.each (data, function (index,values) {/ / parses the Object array $.each (values,function (index2,value) {/ / traversing Object array corresponding to data, the value of each object is stored in value Index2 is represented as the number of objects / / data processing alert (value.name + "" + value.value) according to its own logic. / / TODO: logic});});}, error: function () {alert ("system problem");}})
Let's go on with an example.
This section shares a code example, which is the request processing of JSON data by ajax encapsulated by jQuery.
The code is relatively simple, for experienced personnel can skim, beginners can do a reference.
The code is as follows:
$(document) .ready (function () {$("# bt") .click (function () {$.ajax ({type: "get", dataType: "json", url: "demo/jQuery/ajax/txt/json.txt", success: function (msg) {var data = msg str= "; $.each (data,function (index, n) {str=str+ data [index] .webName +", "+ data [index] .url +", "+ data [index] .age +") }); $("# show") .html (str);}})}) above are all the contents of the article "how to process requests for JSON data in ajax encapsulated by jQuery". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!