Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ajax page load with URL change but no page refresh

Tags:

ajax

php

I have had a search and cannot find what I need, the answers all say it is not possible and a security flaw.

However I have found a Google built website which loads content via ajax and changes the address bar and I need to find out how this is done.

Please have a look at:

http://www.thinkwithgoogle.co.uk/quarterly/people/

And see what you think

like image 671
Friendly Code Avatar asked Dec 05 '25 02:12

Friendly Code


1 Answers

The technique you are talking about is commonly (?) known as pjax

There are several parts to get the effect you are describing:

  1. Manipulating the url and/or headers in the request sent to the server - such that the request is different when part of a pjax request
  2. Server-side logic to honour the URL/headers sent with the request, and return a full html page or html snippet as appropriate
  3. Using the push state method to update the URL in the browser

The last part is specifically what you are asking about, but without the rest of the logic it's not going to be too useful.

like image 120
AD7six Avatar answered Dec 07 '25 16:12

AD7six