Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have got it working but not really sure if this is the recommended way.</p> <p>java script function is</p> <pre><code>$("#sendButton").click(function(){ var gridData = jQuery("#list").getRowData(); gridData = JSON.stringify(gridData); alert("postData stringify data :\n" + postData); postData = postData.replace(); $.ajax({ type: "POST", url: CONTEXT_ROOT+"/json", data : gridData, contentType: "application/json; charset=utf-8", success: function(response, textStatus, xhr) { alert("success"); }, error: function(xhr, textStatus, errorThrown) { alert("error:"+errorThrown+" textStatus : "+textStatus); } }); }); </code></pre> <p>Server code is now</p> <pre><code>@RequestMapping(value = "/json", method = RequestMethod.POST) public @ResponseBody String saveNewCasePackOptions(@RequestBody List&lt;Map&gt; json) { for(Map mJson : json){ String idCasePkOptions = (String)mJson.get("idCasePackOptions"); Long idCasePackOptions = (idCasePkOptions.isEmpty())?null:new Long(idCasePkOptions); Short cypharecommended = new Short((String)mJson.get("cypharecommended")); Short distributorapproved = new Short((String)mJson.get("distributorapproved")); String heightStr = (String)mJson.get("height"); Double height = (heightStr.isEmpty())?null:new Double(heightStr); String lengthStr = (String)mJson.get("length"); Double length = (lengthStr.isEmpty())?null:new Double(lengthStr); String weightStr = (String)mJson.get("height"); Double weight = (weightStr.isEmpty())?null:new Double(weightStr); String widthStr = (String)mJson.get("width"); Double width = (widthStr.isEmpty())?null:new Double(widthStr); String stateString = (String)mJson.get("statuscode"); Short statuscode = new Short(stateString); CasePackOptions casePkOpt = new CasePackOptions(idCasePackOptions, cypharecommended, distributorapproved, height, length, statuscode, weight, width); System.out.println(casePkOpt); casePackOptionsService.save(casePkOpt); } return "Success"; } </code></pre> <p>Things that feel like they need to be done differently</p> <ol> <li>When I try to use $("#list").jqGrid("getGridParam", "data"); instead of jQuery("#list").getRowData(); I was getting id:"1" as part of my Json string</li> <li>When trying to use data : {json: postData} instead of data : postData the json object in firebug was encoded like this </li> </ol> <p>json=%5B%7B%22idCasePackOptions%22%3A%221%22%2C%22cypharecommended%22%3A%221%22%2C%22distributorapproved%22%3A%222%22%2C%22height%22%3A%2214%22%2C%22length%22%3A%2255%22%2C%22statuscode%22%3A%221%22%2C%22weight%22%3A%2214%22%2C%22width%22%3A%221%22%7D%2C</p> <p>Any suggestions would be helpful. Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload