How to splice ajax json and string using jquery

小云云
Release: 2018-10-31 09:58:35
forward
3194 people have browsed it

Organize the documents and search out a jquery splicing ajax json and string splicing code. This article mainly introduces the jquery splicing ajax json and string splicing method. Here is a detailed code. Friends who need it can For reference.

jQuery splices the string ajax

Copy after login

or directly serializes it using $("#formid").serialize(). . .

The above plug-in cannot be applied to input controls with multiple values, such as check boxes and multi-select selects. Next, I will further modify the plug-in to support multiple selections. The code is as follows:

Js code

(function($){ $.fn.serializeJson=function(){ var serializeObj={}; var array=this.serializeArray(); var str=this.serialize(); $(array).each(function(){ if(serializeObj[this.name]){ if($.isArray(serializeObj[this.name])){ serializeObj[this.name].push(this.value); }else{ serializeObj[this.name]=[serializeObj[this.name],this.value]; } }else{ serializeObj[this.name]=this.value; } }); return serializeObj; }; })(jQuery);
Copy after login

Here, I encapsulate the multi-select value into a numerical value for processing. If you need to encapsulate the multi-select value into a string connected by "," or other forms when using it, please modify the corresponding code yourself.

The test is as follows:

Form:

Html code

I have a bike I have a car
Copy after login

Test result:

{age: "aa", interest: ["interest2", "interest4"],name: "dd",vehicle:["Bike","Car"]}

Copy after login

Related recommendations:

vue syntax Detailed explanation of string splicing

How to use ajax to dynamically splice html code

How to implement variable and string splicing in vue

Source of this article: https://blog.csdn.net/lunhui1994_/article/details/54911845


The above is the detailed content of How to splice ajax json and string using jquery. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!