0

I am using Spring Boot for a quiz project. I am doing an ajax request for loading the questions and want to call a javascript function from inside a controller like in Ruby on Rails.

What solution offers Spring Boot to do so? Is that the right way? Or is there a better solution? I couldn't find anything.

7
  • You can call several scripting languages from Java, Javascript being one of them. Those script languages can then access your Java data model. Is this what you are looking for ? Commented Dec 29, 2015 at 0:01
  • Instead of responding with a .html template in the Spring Boot controller, I want to return Javascript. Commented Dec 29, 2015 at 0:05
  • So you are not calling javascript but returning it. If the Javascript is static you can put it into the resources folder of your project, Boot will happily provide that file. If it is dynamic you can have any controller output any string / text. So you can even return Javascript. Commented Dec 29, 2015 at 0:07
  • Maybe do you mean JSONP: docs.spring.io/spring/docs/current/spring-framework-reference/… ? Commented Dec 29, 2015 at 0:21
  • I have a fix Javascript with several methods to be called when a certain action occurs from inside the controller. Sorry for mixing up call and return, but I definitely need to call. Commented Dec 29, 2015 at 0:31

1 Answer 1

1

I realised how to do it. I needed a rest controller which returned an object. That object is automatically a JSON Object, which can be used afterwards. I can now interact with the quiz answers etc.

Sign up to request clarification or add additional context in comments.

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.