I am generating the html using JSON file. Now I need to pass data to the servlet. But the data being passed shows null. I am using jQuery post to pass the data.
My js file has
$.getJSON('input.json',function(data)
{
$.each(data,function(j,feild)
{
if(this.type=="checkbox")
{
$('body #tabs #tabs-3 #server').append(this.display_name).append(INPUT_CHECKBOX).attr({name:this.name,type:this.type}).append(NEWLINE);
}
else
if(this.type=="radio")
{
var radio = '';
var len = feild.values.length;
for (var i = 0; i< len; i++)
{
radio +='<input type="radio" name="group2">'+feild.values[i];
}
$('body #tabs #tabs-3 #server').append(this.display_name).append(radio).attr({name:this.name,type:this.type}).append(NEWLINE);
}
});
The post method contains
function forwarddata()
{
alert('inside the function');
$.post('url',
{gender:$('input[type=radio]').val(),
items:$('input[type=checkbox]').val()!= undefined,
stores:$('input[type=checkbox]').val()!= undefined
});
}
Myjson file has
{
"gender":
{"display_name":"gender:",
"name":"gender",
"format":"string",
"type":"radio",
"format":"string",
"values":["male","female"],
"isMandatory":"true"
},
"items":
{ "display_name":"items:",
"name":"items",
"format":"string",
"type":"checkbox",
"values":[1,2,3,4],
"isMandatory":"true"
},
"stores":
{ "display_name":"stores:",
"name":"motion",
"format":"string",
"type":"checkbox",
"values":[a,b,c,d],
"isMandatory":"true"
}
}
When I try printing the data in the servlet it says null… Kindly explain the correct way of posting the data.
I changed my JSON data.Added name attribute and the below function worked just fine
Thanks:)
}