Hi my setDefaultPoint controller returns map as a json… the code is below
def setDefaultPoint = {
if (springSecurityService.isLoggedIn()) {
def officeId = params.officeId
def officeRoleInstance=OfficeRole.get(officeId)
def company= officeRoleInstance.company
def defaultPoint = officeRoleInstance.distanceChart.officePoint
def map = [defaultPoint:defaultPoint]
map << [company:company]
def json = map as JSON
render json
}
the ajax call which sends to request to this controller is
function setDefaultPoint(){
var officeId = $('#clientTrip_officeId').val();
$.ajax({
url:"${createLink(controller:'clientTrip',action:'setDefaultPoint')}",
dataType: "json",
data:({officeId: officeId}),
success: function(data) {
// here i want to get the id and name of default point and id and name of company...
console.log('id of defaultpoint is---"+????)
console.log('name of default point is---"+????)
console.log(id of company is-----------"+?????)
}
});
}
from json i am passing two different object.. so how to get the propirties of those object… both defaultPoint object and Company object has fields called id and anme
the response is looks like
{"defaultPoint":{"class":"com.springpeople.steer.trips.Point","id":3,"name":"MG road"},"company":{"class":"com.springpeople.steer.partymodel.parties.Company","id":5,"addressPermanent":{"class":"Address","id":3},"contactDetails":null,"name":"Infosys","offices":[{"class":"OfficeRole","id":6}],"organizationRoles":[{"class":"OrganizationRole","id":5}],"panNumber":null,"serviceTaxNumber":null,"tanNumber":null}}
Since the returned dataType is specified as
json, thedataargument passed to the function assigned tosuccesswill be the JavaScript object parsed from the returned json string, so long as the string is valid json. thedatapassed in the ajax call doesn’t need the parens around it. This should work