javascript - Will a 'JavaScriptResult' return to an 'eval' in MVC and effect site performance? -
i looking ways redirect ajax request , came across solution:
return javascript("window.location = 'http://www.google.co.uk'");
i told might wrapped in eval upon return, can change how code compiled , effect efficiency.
eval("window.location = 'http://www.google.co.uk'"); //actually gets executed
i told change return redirect url.
two questions this:
1) executing eval
, in 'success' through ajax request, effect compilation of other javascript?
2) happens when return post javascript
actionresult
? run inside eval
(implicitly)?
// in mvc controller [httppost] public actionresult myaction() { return jsonresult("window.location = 'url'"); } // in javascript $.ajax({ type: 'post', url: '/myaction' });
javascriptresult
returns javascript client, can, instance, access <script>
element:
<script src="/mycoolcontroller/givemescript?param5=7"></script>
how javascript gets executed you.
i don't see why performance of eval()
concern if objective redirect page, sounds pretty questionable approach (especially if involves eval()
).
why not return jsonresult indicates redirect using pre-decided convention, , have script act accordingly:
// in controller return jsonresult(new { redirectto = "http://www.google.co.uk" });
// in script $.ajax({ type: 'post', url: '...', success: function (result) { if (result.redirectto) { window.location = result.redirectto; } // handle result if not redirecting ... } });
Comments
Post a Comment