This is a migrated thread and some comments may be shown as answers.

what is the proper way to navigate away from a view before showing it?

3 Answers 69 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
user1843640
Top achievements
Rank 1
user1843640 asked on 08 Dec 2012, 07:24 PM
When an $ajax call is made in a view's show or beforeShow event, how/when/where should we navigate to another view from the $ajax success or error callback?  What I am currently doing does not work properly.

Consider the following example with 3 views:

initialView
errorView
ajaxView

  • user starts on initialView and clicks a link to navigate to #ajaxView
  • ajaxView does an $ajax call in its beforeShow event.  
  • on success, the $ajax success callback does some processing and the view is displayed
  • on error, the  error callback evaluates the error and navigates to #errorView
The above steps don't work.  errorView is not displayed.  Here is the jsfiddle for above.


3 Answers, 1 is accepted

Sort by
0
Petyo
Telerik team
answered on 10 Dec 2012, 02:32 PM
Hello,

You miss the e.preventDefault call. Check the docs on the corresponding topic. In addition to that, you have to create a synchronous ajax call.

All the best,
Petyo
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
user1843640
Top achievements
Rank 1
answered on 10 Dec 2012, 07:53 PM
I'm aware of e.preventDefault but I don't have access to the event (e) from the call back.  In most cases the ajax calls need to be async so that the UI is responsive... so I need another solution.  An example use case is authentication  an async data request is made, the error callback receives the 401 status code and redirects to the login view.  I am open to suggestions.
0
Petyo
Telerik team
answered on 11 Dec 2012, 07:58 AM
Hi,

In that case, you may consider handling the click event, performing the ajax call, and (if everything is correct), navigate to the respective page using app.navigate. 

Regards,
Petyo
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
General Discussions
Asked by
user1843640
Top achievements
Rank 1
Answers by
Petyo
Telerik team
user1843640
Top achievements
Rank 1
Share this question
or