Skip to content

Instantly share code, notes, and snippets.

@s-hiroshi
Last active October 12, 2015 00:02
Show Gist options
  • Save s-hiroshi/98eeaa7c3d00c7f72c9b to your computer and use it in GitHub Desktop.
Save s-hiroshi/98eeaa7c3d00c7f72c9b to your computer and use it in GitHub Desktop.
/**
* POSTパラメーター取得
*
* POSTメソッドのパラメーターをJSON形式で返します。
*
* @method getData
* @public
*
* @param {Array} ids コントロールのid配列です。
* @return {Mixed(JSON|Boolean)} POSTパラメーターをJSON形式で返します。
* 引数で渡されたidに対応する要素が1つもないときはfalseを返します。
*/
function getData( ids ) {
var data = {};
if (!arguments.length > 0) {
return false;
}
if ( !ids instanceof Array ) {
return false;
}
$.map( ids, function ( id ) {
if ( $( "#" + id ).length > 0 ) {
data[id] = $( "#" + id ).val();
}
} );
if ( $.isEmptyObject( data ) ) {
return false;
}
return data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment