java - Problems passing data to jquery's getJSON() - Will not accept map -
i trying serialize form (jsp/struts 1.1) , put object or map or whatever jquery's .getjson() method needs. here js code:
// function makes ajax call, passing entire form action class function ajaxcallwithform(inputurl, formname, onreturnfunction) { var formasmap = serializeform(formname); $.getjson(inputurl, formasmap, onreturnfunction); } function serializeform(formname) { var obj = {}; var = $('#'+formname).serializearray(); $.each(a, function() { if (obj[this.name] !== undefined) { if (!obj[this.name].push) { obj[this.name] = [obj[this.name]]; } obj[this.name].push(this.value || ''); } else { obj[this.name] = this.value || ''; } }); return obj; }
this results in java.lang.illegalargumentexception
on end (something beanutils.populate servlet method).
if set 2nd of 3 parameters of .getjson() call this, works fine , data shows in form object in java end:
// function makes ajax call, passing entire form action class function ajaxcallwithform(inputurl, formname, onreturnfunction) { $.getjson(inputurl, {"vehiclekeynum":12345, "vehicleid":"12345", "rand":math.random()}, onreturnfunction); }
i have tried creating string proper syntax includes data form , results in same thing. may have syntax wrong that. @ rate, main problem that:
1) .getjson() method accepts, "a map or string sent server request." 2nd parameter (see http://api.jquery.com/jquery.getjson/)
2) passing think "map"
3) getting java.lang.illegalargumentexception
, don't know go here
if want submit form server, can use jquery's serialize() or serializearray() method.
$.getjson(inputurl, $(formname).serialize(), onreturnfunction);
you should have data returned serialize/serializearray method populated in form bean if element names matched right.
here working example of serialize method (copied jquery website)
java.lang.illegalargumentexception
beanutils.populate
servlet method due data type mismatch between data submitted , data on form bean.
Comments
Post a Comment