I was looking at some ways to redirect from an AJAX request and came to a solution:
return JavaScript ("window.location = 'http://www.google.co.uk'"); I was told that it could be wrapped in an eval on its return, which can change the code and how the effectiveness can change. eval "Window.location = 'http://www.google.co.uk"); // is actually executed
I was asked to change it to return the redirected URL.
Two questions about this:
1) In order to implement an 'success' through an AJAX request, will the compilation of other Javascript be affected?
2) When I javascript ActionResult from my post? Does it eventually go inside a eval (fully)? MVC controller in [
// [HTTP post] Public action MyAction () {back JsonResult ("window.location = 'url'"); } // javascript $ .ajax ({type: 'POST', url: '/ MyAction'});
JavaScriptResult simply gives JavaScript to the customer, so that you For example, it should be & lt; Script & gt; element can be used by:
& lt; Script src = "/ MyCoolController / GiveMeScript? Param5 = 7" & gt; & Lt; / Script & gt; This is how Javascript is executed depends on you.
I really do not know why eval () will show why the concern is to redirect your page to the page, but it seems like a very suspicious approach (Especially if it contains eval () ).
Why not just a Jason result that indicates a redirect using some pre-defined conference, and then your script works accordingly:
In the Administrator return < Code> // JsonResult (new {redirectTo = "http://www.google.co.uk"}); // script $ .ajax ({type: 'POST', url: '...', success: work (results) {if (result.redirectTo) { Window.location = result.redirectTo;} // handle the result when there is no redirect ...}});
No comments:
Post a Comment