You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
.serialize() should be a thing, but it shouldn't be like jQuery. Instead of providing .serialize() and .serializeArray(), the argument should determine what type of output is generated.
.serialize() - No argument, defaults to 'url'
.serialize('url') - String of URL encoded data
.serialize('array') - Array of key / value pairs
.serialize('object') - Object with named properties
var data = {};
$(form).find('input, select').each(function()
{
if($(this).attr('type') == "submit")
{
return;
}
var name = $(this).attr('name');
var value = $(this).value();
if($(this).attr('type') == 'checkbox')
{
if($(this).prop('checked'))
{
value = true;
}
else
{
value = false;
}
}
// If this input name has already been used
if(data[name] !== undefined)
{
// Is it an array? If not, convert it
if(!Array.isArray(data[name]))
{
data[name] = [data[name]];
}
// Push value to input array
data[name].push(value);
}
else
{
// Otherwise, save the value by itself
data[name] = value;
}
});
Activity
itsrachelfish commentedon Jan 12, 2017
Something like this might be helpful: