I'm using the serializearray with success, but now I need to make a trick.
How can I build this array, but defining that some inputs must have a specific class, so I 开发者_如何学运维can make diferent sql queryes based on that?
this is what I'm now using
$.each($("form[name='admin']").serializeArray(), function(i, campo)
I need it like that, but also need to add something to compare, per example
if(something) {
$sql_query = 'select * from admin';
} else {
$sql = 'select * from teste';
}
Use .map()
and filter the collection based on your own requirements, then call serialize.
$('#myForm :input').map(function(i,e){
// test against e, return the object if it's
// a good fit, otherwise return null
var $e = $(e);
return ($e.hasClass('foo') ? $e : null);
}).searializeArray();
You can do something like the following. Chances are you don't need to use .serializeArray
because you want to pass the values through a POST request:
var postString = $('form[name='admin'] input.classToFind').serialize();
精彩评论