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
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);
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
Test result:
{age: "aa", interest: ["interest2", "interest4"],name: "dd",vehicle:["Bike","Car"]}
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!