URL created by pushstate of History object

154 Views Asked by At

I am learning how to cange my URL to show query string parameters sent to server

I am taking some data from user, making an ajax call to server, when server returns data i show that to user,,, So, if my URL earlier was abc.com . and If I use pushstate to append query string parameters to URL i.e. to make it abc.com?param1=val1&param2=val2 ,

Would this new URL be the actual URL for those 2 parameters taken from user. I mean If I copy and send this link to somebody : abc.com?param1=val1&param2=val2

would it open that abc.com to show data results for these two parameters?

Thanks in advanceenter code here

1

There are 1 best solutions below

2
On

It does not get the data for for abc.com?param1=val1&param2=val2 but instead gets data for abc.com, the default

But you can fix this either using JS or Server-side prog lang.

  1. If you're using JavaScript, you can do it by parsing document.URL yourself and then load the data based on the params. (Not recommended)
  2. Else if on the server, directly serve the content for abc.com?param1=val1&param2=val2

The second method is highly recommended.