Sen guys, I do some work where I have a large collection of forms. It seems that they are not “sent” in the traditional way (for example, using the submit button). I need a way to collect all the names and values of all form data when a link is clicked (document.location is then used to redirect).
I want the names to remain intact so that I can use a simple PHP script to work with the data.
any suggestions?
May I suggest Serializing the form for JSON :
$.fn.serializeObject = function() { var o = {}; var a = this.serializeArray(); $.each(a, function() { if (o[this.name]) { if (!o[this.name].push) { o[this.name] = [o[this.name]]; } o[this.name].push(this.value || ''); } else { o[this.name] = this.value || ''; } }); return o; };
and then you can:
var formArray = $("#myform").serializeObject();
$.fn.valuesArr = function() { var a = []; jQuery.each(this, function(i, field){ a.push($.trim(field.value)); }); return a; }
:
var myArr = $('input', $parentJQelem).valuesArr();
-
function submit(form) { var form = $(form); $.ajax( { data: $.param( form.serializeArray()), dataType:'script', type:'post', url: form.attr("action")}); }
"serializeArray()" "serialize()", ajax , .
, , , , .
cletus .
, JSON:
//this is my object I will fill my array with function myObject(name, value) { this.name = name; this.value = value; } var arr = $.map( $('span'), function (item) { var $item = $(item); //no need to $(item) 2 times return new myObject( $item.attr("name"), //name field $item.text() //value field ); } );
arr myObject, name value.
arr
myObject
name
value
$('span').
$('span')
.
example -
,
[ []]: 2
- [type] []: 2
Source: https://habr.com/ru/post/1723773/More articles:UISearchBar in UITableView - uitableviewJava collection filtering - javaМожно ли запускать циклы в функциональных методах тестирования? - rubyMeasuring network time on a website - phpAnalysis of user input according to search criteria - javahow to check users leave page - javascriptMany new items in SharePoint - content-typeC # mvc dynamically creates a controller from a string name - eval? - c #Как проверить правильность URL-адреса flickr - flickrHide text from printing - htmlAll Articles