2

Why do you need JavaScriptResult as a response?
Doesn’t it break the pattern of clean separation of concerns? Can you suggest me some cases where this will be useful?

1 Answer 1

4

The sole purpose of JavaScriptResult is to set the ContentType to application/x-javascript.

You might want to use this if you have an action which returns a .JS file to the browser. For example, you could write an action which concatenates all of your JavaScript files together, so that you could return them in one request instead of many. You might also want to generate JavaScript from a template.

I have seen some blog posts implying that JavaScriptResult will cause the returned file to be executed within the context of the current page. This impression apparently comes from the release notes. But I can't see any mechanism by which that would actually happen in the source code. In other words, in order to get this behavior, you would have to write code within the page causing it to happen. Simply using JavaScriptResult will not have this effect. As far as I can tell, it is simply serving up a js file.

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.