-6

I'm trying to create a real-time chat on my website. One of the functions I want to imitate is how facebook.com/messages changes not only content of the webpage but also the url without refreshing. I think this is a lot cleaner more efficient.

My current process is just a ("#class_name").click with a var id = $(this).attr("id") running with an Ajax.

paradoxparabola
  • 73
  • 1
  • 10

2 Answers2

0

Yes, it uses the Ajax Polling technique for that.

Ajax helps you to pull out data from the source without refreshing the whole web page. You can also fetch a whole page with the .load() function.

For more info about .load(): http://api.jquery.com/load/

And you can change the location url of the browser in real time without refreshing the whole page with JavaScript.

Just Check: Modify the URL without reloading the page

Community
  • 1
  • 1
Saini
  • 734
  • 3
  • 8
0

To add and modify history, use history.pushState() and history.replaceState() methods, respectively.

window.history.pushState('username2', 'Title', '/username2.php');

To know more visit: History API

The only way to create single page apps is to use Angular JS. To know more visit: Angular JS

Manikiran
  • 2,618
  • 1
  • 23
  • 39
  • "the best way"? that´s very opinionated, it is ONE way. – andyrandy Jul 18 '16 at 09:24
  • Or you could use jQuery and simulate it, just like the op is trying to do (I know its not professional but still an option). – Manikiran Jul 18 '16 at 09:26
  • you really don´t need jquery for that...in fact, you don´t need jquery for anything anymore :) – andyrandy Jul 18 '16 at 09:48
  • I disagree! "It's all about performance and development speed..." And even if it wasn't needed then why would there be millions of users still using jQuery? – Manikiran Jul 18 '16 at 09:56
  • performance and development speed: use react. especially when it comes to performance, jquery is the wrong way. you are also not faster in any way with jquery if you know vanilla js. and millions of users still use jquery because they don´t know better and because many plugins are built with jquery. eithe way, my point was: you can´say that "angular is the best way to create single apps", because that´s only your opinion. – andyrandy Jul 18 '16 at 10:01