I can not quite understand how to implement it so that when an AJAX request is made, the script only pulled out that part of the site that is different. Suppose I have a website with two pages, if I access the first page directly and upload the content of the second page through this page, how can I find out what to pull out from the whole page ... If you initially make the second page only with the necessary content without all, then it will not be possible to address it directly ... In general, I think my question is clear ... give some material on this or explain it yourself, thanks in advance!

    2 answers 2

    And where does the History API? Suppose you are now at first.html. And you have a common content block for two pages (div # content). With this query, you can get the page second.html, take only the part that is contained in the div # content and replace the content of the div # content on the current page (first.html). Contact directly to second.html is also possible.

    $.ajax({ url: "second.html", }).done(function( res ) { $("#content").html( $(res).find('#content').html() ); }); 
    • Yes, the solution is suitable, but for some reason I don’t look for #content inside res ... the existence of the element is 100%, I checked everything through the console ... undefined gives out - Lgunchik
    • I found a solution to the problem of choosing an element, for some reason jQuery requires that #content be in another block, and I had it in the body, so I wrapped #content into the #super_content block and it all worked, thanks! - Lgunchik

    Return data from the server, depending on what type of request. For example, if AJAX, then return only the insides of the body, otherwise it will also be wrapped in binding.

    JQuery adds a header: X-Requested-With = XMLHttpRequest

    So in the server part of your application, you can check:

     function isAjax (headers) { return headers.get('X-Requested-With') == 'XMLHttpRequest'); }