I have a JSON array generated from a form
<script type="text/javascript">
$(function() {
$('#btn').click(function() {
var formData=JSON.stringify($('#sform').serializeObject());
// $('#rValues').text(formData);
$.get('Partition',"fdata="+formData,function(fJson) {
$.each(fJson, function(key,value) {
if(fJson!=null){
}
});
});
$("#rValues").show();
return false;
});
});
$.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;
};
</script>
i'm trying to read and print the entire form values in Partiton.java(servlet) but not able to do so.
String data = request.getParameter("fdata");
System.out.println(data);
you will not get fdata by request.getParameter("fdata").
but you will get all form field values by request.getParameter("your form field name given for fields").
at client side : to send form data to servlet
$.ajax({
url:'servlet',
data: $("#form1").serialize(),
success: function (data) {
}
});
at servlet : request.getParameter("your form field name given for form fields").
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.