Sean Gofus - Web Design and Development

Dataminer - A jQuery Plugin

Click To Enlarge

Dataminer is a lightweight, easy-to-use jQuery plugin to get all the data from a form and format it into an JSON object. Dataminer makes it easy to take form values, turn them into JSON and POST them to a server using AJAX.

When using the standard jQuery $.ajax method it can be tedious if you have a long form and want to POST the values to the server using JSON. One must explicitly set the keys and values for the JSON string.


$.ajax({
   url: '/your/cool/script.php',
   dataType: 'json',
   data: {"key1": "value of key one","key2": "value of key two"}
 });

To avoid having to explicitly set the values for the data parameter you can simply call the Dataminer and target the form you wish to get the values from.


$.ajax({
   url: '/your/cool/script.php',
   dataType: 'json',
   data: $('#formid').dataMiner()
});

Dataminer then will take all the form values and format them into a JSON object using the 'name' attribute on the fields as the key. If don't want to use the 'name' attribute as the key then Dataminer will also except custom selectors.


//THE ID ATTRIBUTE IS NOW THE KEY
$.ajax({
   url: '/your/cool/script.php',
   dataType: 'json',
   data: $('#formid').dataMiner({customSelector:'id'})
});

Read the full documentation on the plugin's download page on Github.

DOWNLOAD ON GITHUB

Share