언어&플랫폼/Html/JQuery 2013. 10. 16. 02:08



var contact = new Object();
contact.firstname = "Jesper";
contact.surname = "Aaberg";
contact.phone = ["555-0100", "555-0120"];

var memberfilter = new Array();
memberfilter[0] = "surname";
memberfilter[1] = "phone";
var jsonText = JSON.stringify(contact, memberfilter, "\t");
document.write(jsonText);
// Output: 
// { "surname": "Aaberg", "phone": [ "555-0100", "555-0120" ] }


간단한 활용

function filter(){

var item = new Object();

item.storage = false;

item.device = $('#in_filter_device').val();

item.process_name = $('#in_filter_process').val();

item.level = $('#in_filter_level option:selected').text();

iitem.skips = parseInt($('#in_filter_skip').val(), 10) || ''; // 숫자 외의 것이 입력 되었을 시, NaN(not a number)가 삽입 된다.

item.limits = parseInt($('#in_filter_limit').val(), 10) || '';

item.msg = $('#in_filter_msg').val();

item.important = $('#in_filter_ck_important').prop("checked");

item.last = $('#date_option').children().children().children('.active').text();

var filter = new Array();

var cnt = 0;

filter[cnt++] = "storage";

if(item.device != '')

filter[cnt++] = "device";

if(item.process_name != '')

filter[cnt++] = "process_name";

if(item.level != '')

filter[cnt++] = "level";

if(item.skips != '')

filter[cnt++] = "skips";

if(item.limits != '')

filter[cnt++] = "limits";

if(item.msg != '')

filter[cnt++] = "msg";

filter[cnt++] = "important";

if(item.last != '')

filter[cnt++] = "last";

var jsonText = JSON.stringify(item, filter, "\t");

  //console.log(jsonText);

return jsonText;

}

function getLogList(){


var jsonText = filter();

$.ajax({

type : 'post',

url : restURL + 'log/',

headers:{

},

contentType:"application/json",

data: jsonText,

success : function(data) {

console.log('SUC');

console.log(data);

},

error : function(request, status, error) {

console.log('fail');

console.log("code:"+request.status+"\n"+"message:"+request.responseText+"\n"+"error:"+error);

},

});

}




[참조] http://msdn.microsoft.com/ko-kr/library/ie/cc836459(v=vs.94).aspx

'언어&플랫폼 > Html/JQuery' 카테고리의 다른 글

jquery 모든 문자 변경  (0) 2013.10.16
[javascript] parseint resturn NaN  (0) 2013.10.16
ajax POST (request payload)  (0) 2013.10.16
jquery select box 제어  (0) 2013.10.10
[jquery] ajax json 동기 호출  (0) 2013.10.10
posted by cozyboy
: