Adding this function to your JS code allows you to serialize any object with the attributes "name" and "value". I usually use it to serialize forms. I know that you said that these controls are formless, but I would suggest that this can be used to serialize any object with the name / value attribute. It also looks simple enough to change it to look for other attributes of an object, such as an ID. It's hard to say exactly what you are doing there, because you are not showing the definition of "data" or the use of "values"
$.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; };
Then just add it to url string
var dataToPassToAjax = 'allData=' + myObject.serializeObject();
If you pass only one value, you do not need to serialize.
$.post("/scripts/php/process.php",{ 'data': 'data=' + $('li.tag.active').id, funcName : 'tagResults' }).
then in process.php just get the value $ _ REQUEST ['data'] , and it will have your identifier
source share