Handle get errors (403,404,405) with jquery

1

I'm using history API to load the clicks on the menu, in a div #content, okay so far so good, however I'm handling the errors by JQUERY even look at it

$('a').click(function() {
    pageurl = $(this).attr('href');
    if(pageurl!=window.location){
        window.history.pushState({path:pageurl},'',pageurl);
        }
     $('#conteudo').load($(this).attr('href'), function(responseText, statusText, xhr)
                {

         if(xhr.status == 403) { 
             $('#conteudo').load("/error/error403");

         }
         if(xhr.status == 404) { 
             $('#conteudo').load("/error/error404");

         }
         if(xhr.status == 405) { 
             $('#conteudo').load("/error/error405");

         }

 });

      return false;
    });

I would like the opinion if this is really feasible, since I am using VRAPTOR and can only imagine this way of treating the errors in an "efficient" way, does anyone have problems or can you see a possible problem?

If this is relevant, if the controller does not exist it sends the non-existent page error (404), if the user tries to access a method not allowed, returns the 403 (forbidden) and so on ..

EDITED for question 2:

Well, I have the following structure

I have the index.php that contains 2 divs

<div id="menu"> 
e <div id="conteudo">

When you load the index, it pulls with .load (/ test / menu) to the div = menu

It works perfectly, except that if I type in the navigated / test / LinkClicado or / test / menu, it will simply open only the respective ones without the correct division, the linkClicado will open only the html referring to it without the MENU above ... and so if I open the link / test / menu, it will show only the menu without the content

How do I open the / test / LinkClicado link to open the COMPLETE page that would be / test / index, but in the position relative to the link typed in the case / test / LinkClicado

    
asked by anonymous 22.05.2014 / 20:20

1 answer

1

According to the jQuery.load () documentation, if you compare the value of the status with the error string, you can determine that the loading action resulted in an error.

With this, as it seems that all your error URLs change just as to the HTTP Response Code , you would just have to concatenate the unchanging part of the string to the status code:

$('#conteudo').load($(this).attr('href'), function(responseText, statusText, xhr)
                {
    if( status == "error" ) {

        $( '#conteudo' ).load( '/error/error' + xhr.status );
    }
});

Just note that you should have a fallback for the second call to jQuery.load () for the error, also fails and you have how to debug.

As for the second question your biggest problem lies in the obstrusiveness of JavaScript. A Web Application should work only with HTML and server-side programming. Then you add CSS and JavaScript.

That is, your lad server programming, when you receive a certain URL will have to return in response to the browser everything that the GUI needs to function, this includes menu and body.

After the visual interface is ready, JS would make it richer, allowing dynamic navigation, for example.

    
22.05.2014 / 20:40