Say I have this
<div id="x" data-id='1' data-prop1='peace' data-prop2='out'>Text</div>
in jQuery i can get the data like so
var row = $('#x')
var x = {
id : row.data('id'),
prop1: row.data('prop1'),
prop2: row.data('prop2'),
};
it would be way more convenient if I could do something like this
var row = $('#x');
var x = row.data.serialize();
Anyone know how to do this?
EDIT:
I forgot to mention that var x = row.data() will do the job but there's all this jquery junk in there.
I want to send the data as part of an ajax request once i've got it.
eg,
remove: function (row, g, o) {
if (confirm(o.deleteConfirmation)) {
var url = o.deleteAction;
var data = row.data();
$.ajax({
url: url,
type: 'POST',
// THIS WORKS
// data: {
// id: row.data('id'),
// applicationId: row.data('applicationId')
// },
// THIS DOESN'T
data : data,
success: function (result) {
g.html(result.Html);
methods.rebind(g, o);
}
});
}
}
EDIT : My 'Working' Solution
I got it working by killing the jQuery{some number} thing out of the data object
first I grabbed this from here
if (!String.prototype.startsWith) {
String.prototype.startsWith = function(str) {
return !this.indexOf(str);
};
}
Then I had to do this:
var rowData = row.data();
var data = {};
for(var propertyName in rowData) {
if(!propertyName.startsWith('jQuery'))
data[propertyName] = rowData[propertyName];
}