Doubt about $ .getJSON and history.pushState

1

I'm studying about history.pushState and I plan to develop a site as a way of studying like this link

In terms of jQuery (function to load the new content) I understood perfectly, but I had some doubts:

  • Is there a difference between window.history.pushState or only history.pushState ?
  • What is the function of the first attribute (in this case "null") window.history.pushState(null, "titulo", "novaurl") ?
  • The second attribute, responsible for the new title, does not work. Proceed with document.title = "novoTitulo" is the correct form?
  • In the case of the cite mentioned as an example, $.getJSON is used to return the requested data, and this part I even understood how to return the data from PHP, but, my big question is: if I have a big website, how do I return all the data being that I use Templates for PHP and HTML help (including database queries, etc), is it possible or do I have to change my structure? Because, I realized the returned data is according to the cid variable passed through jQuery, and the data is returned with a echo json_encode()... ?
  • Is there even incompatibility of the window.history.pushState() function with IE?
  • I've seen in Github a library called History.js . For what does it serve since the history function is already native to browsers (I'm asking why I really could not understand)?
  • Thanks!

        
    asked by anonymous 09.04.2015 / 23:22

    1 answer

    0

    I'll answer point by point about the history part. As for getJSON , I think it's the case for a separate question, as I said in the above comment (do not get mean, we're crazy for organization here on the site, ideally the questions should be focused so they can help to other people).

      

    Is there a difference between window.history.pushState or only history.pushState ?

    No. In browsers, window is the global object. Everything that hangs in window can be accessed with or without window. .

      

    What is the function of the first attribute (in this case "null") window.history.pushState(null, "titulo", "novaurl") ?

    This is one of the most interesting things about the History API. You can pass an object that represents the state of the application at that particular moment. When the person returns to that point (via browser's back button, for example), a popstate event is triggered, and the listener of that event receives the corresponding state object. So you can restore the application state without having to fetch data from the server.

    The object to be passed must be a simple object that can be serialized (that is, without functions / methods, and I would also avoid inherited content via prototype). The serialized object should occupy a maximum of 640k characters.

      

    The second attribute, responsible for the new title, does not work. Proceed with document.title = "novoTitulo" is the correct form?

    The purpose of the second argument for pushState is not to change the page title, but to save a title in the history. If you want to change the current title, you actually need to use document.title = "novoTitulo" .

      

    Is there any incompatibility of the 'window.history.pushState () function with IE?

    Yes, from what I know it's only available from IE10.

      

    I've seen in Github a library called History.js. For what does it serve since the history function is already native to browsers (I'm asking why I really could not understand)?

    The purpose is to offer something close to the official API in a browser where it is not supported, such as versions of IE prior to 10. The library uses fallback mechanisms such as hashes to handle states and URL exchanges.

    Relevant documentation:

    12.04.2015 / 04:43