Get data in Forms
You could use the serializeArray
for the forms. You just need to parse it in the correct way. An example method is provided below
$.fn.serializeObject = function()
{
var o = {};
var a = this.serializeArray();
$.each(a, function() {
if (o[this.name] !== undefined) {
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;
};
Example in action: http://jsfiddle.net/sxGtM/3/
Get content in HTML elements
You can get the content of an div or something else by using the document.getElementById
method and then the innerHTML
property
var MyDiv1 = document.getElementById('DIV1');
var content = MyDiv1.innerHTML;
Post object to server using jQuery
function sendData() {
$.ajax({
url: '/example',
type: 'POST',
contentType: 'application/json',
data: <Your JSON Object>,
dataType: 'json'
});
}