0

How to get JSON response in jQuery Ajax in Spring Mvc? this is my ajax code

 $.ajax({
       type: 'POST',
       url: "fetch",
       dataType: 'json',
       data:  {clientidedit:clientidedit},
       success: function(data) {

       },
       error: function(jqXHR, textStatus, errorThrown) {
           alert("error");
       }

  });

here is my service. this will return a string.How can i get each data in ajax response?

if (StringUtils.isEmpty(clientId)) {
        resObj.put("clientId", org.json.JSONObject.NULL);
    } else {
        resObj.put("clientId", clientId);
    }

    if (StringUtils.isEmpty(clientName)) {
        resObj.put("clientName", org.json.JSONObject.NULL);
    } else {
        resObj.put("clientName", clientName);
    }
    array.put(resObj);
}

try {
    resObjForTable.put("aaData", array);
} catch (JSONException ex) {
    Logger.getLogger(SabbServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
}
return resObjForTable.toString();

Thanks in advance....

1
  • What is the return type of your service? Commented Nov 27, 2015 at 8:00

2 Answers 2

1

Your controller class method should be like this

    @RequestMapping(value = "fetch")
    @ResponseBody
    public Object methodName() {

        // Your implementation.

        return resObjForTable.toString();
    }
Sign up to request clarification or add additional context in comments.

Comments

0

Your C# code should like this that return "Json" Try this

function JsonResult FunctionName (Param){
if (StringUtils.isEmpty(clientId)) {
        resObj.put("clientId", org.json.JSONObject.NULL);
    } else {
        resObj.put("clientId", clientId);
    }

    if (StringUtils.isEmpty(clientName)) {
        resObj.put("clientName", org.json.JSONObject.NULL);
    } else {
        resObj.put("clientName", clientName);
    }
    array.put(resObj);
}

try {
    resObjForTable.put("aaData", array);
} catch (JSONException ex) {
    Logger.getLogger(SabbServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
}
return json(resObjForTable);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.