0

I want to pass a java object to javascript. I am using spring as backend. For html I just passed the object to my model and I can call them in html through the "$" parameter. But in javascript it seems that this will not work.

So my question is. How can I call a passed object (which is already a json string) in javascript?

// java side
model.addAttribute("data", jsonObject);

// javascript side
// ???

2 Answers 2

1

You need to use ajax and call the api in the from spring controller.

@RequestMapping(value = 'url', method = RequestMethod.methodType)
public @ResponseBody List < SomeClass > getAllData(pass parameter here) {
  return someResultFromHere;
}
Sign up to request clarification or add additional context in comments.

Comments

1

You should add an ajax call for that specific api endpoint and use the name of the model to extract anything with in.. As brk stated you will call it and it will get value.Then you can use that to parse the data comming from the beckend of your server this is an example of the code.

 // java side 
model.addAttribute("data", jsonObject);

//ajax side
$getJSON('http://<yourserverip>:<yourport>/myapi/values/', function(data){
 console.log(data.<yourValue>);
});

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.