简体   繁体   English

在AJAX POST上自定义序列化表格?

[英]Customized Serialize form on AJAX POST?

I want to serialze form data on an AJAX POST request and 我想在AJAX POST请求上序列化表单数据,并且

$("#formid").serialze() isn't suitable for me. $("#formid").serialze()不适合我。

Is there a way I can get the results in a better format . 有没有一种方法可以使我获得更好的格式的结果。 Currently $("#formid").serialze() gives me the result as 当前$(“#formid”)。serialze()给我的结果是

`poststring="csrfmiddlewaretoken=bb9SOkN756QSgTbdJYDTvIz7KYtAdZ4A&colname=SPORT&datatype=VARCHAR2&field_size=20&null_constraint=1&default_val=&colname=HELLO&datatype=VARCHAR2&field_size=20&default_val=&colname=JUDY&datatype=VARCHAR2&field_size=20&default_val=&tablename=&fsize=&preview_flag=`

I want the POST request object to be 我想要POST请求对象

{"colname":[HELLO,JUDY,SPORT]...............} {“ colname”:[HELLO,JUDY,SPORT] ......}

with multiple row form inputs as arrays (if you know what I mean). 具有多个行形式的输入作为数组(如果您知道我的意思)。

I thought of parsing the output from serialize() but then it could be buggy and can break with tricky column data. 我曾想过分析serialize()的输出,但随后可能会出错,并且可能会遇到棘手的列数据。

I need the POST response to be in the format I mentioned 我需要POST响应采用我提到的格式

I guess you want to build a object has some key, and each key has an array to be value? 我猜您想构建一个具有一些键的对象,并且每个键都有一个数组作为值? serialze() can`t solve your problem, you may need to write a new function. serialze()无法解决您的问题,您可能需要编写一个新函数。


you can set class to each inptu of your form,like class="colname" class="dataType", and you need to use $('.someClass').each() or other method to check your input and use array.push() to build an array.finally use some array to build a new object like you want. 您可以将class设置为表单的每个intutu,例如class =“ colname” class =“ dataType”,并且需要使用$('。someClass')。each()或其他方法来检查输入并使用数组。 push()建立一个数组,最后使用某个数组建立一个想要的新对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM