1

There is a website which takes some input from user and store it somewhere. Now, in the input field, I type - naman#jain . Now a url will be formed like - www.website.com/?name=naman#jain in client side . And #jain is also sent to server. As I read about it after # browser ignores everything. Correct me if I am wrong. So how this actually happens?

I tried to ask question in comments here-Usage of hash in URL but could not find appropriate answer.

Community
  • 1
  • 1
Naman
  • 991
  • 2
  • 10
  • 20

2 Answers2

0

When form is submitted form parameters are url encoded. So the input naman#jain will result into something like

www.website.com/?name=naman%23jain

This is how it's sent to the server. There GET parameters are encoded back and used.

dfsq
  • 191,768
  • 25
  • 236
  • 258
0

You can access the hash via:

console.log(window.location.hash);

To be able to store the hash, you can use for instance this code:

$.ajax({
  type: "POST",
  url: "save.php",
  data: { name: $("#name").val(), hash: window.location.hash }
})
  .done(function( msg ) {
    alert( "Data Saved: " + msg );
  });

Ps. This is untested, so it might fail to run :-) Maybe there are better ways to do it, like you could save the hash to a hidden field and then do the form serialize.

Olavxxx
  • 196
  • 10