Reputation: 103810
I have a variable but I can't use it the way I want, please help!!
var test = window.location.hash;
$('div').load("test.php?id="+test);
The request keeps on being :
XHR finished loading: "http://localhost/test-site/test.php?id=".
and ignores my variable...
Upvotes: 2
Views: 87
Reputation: 92983
window.location.hash
will begin with a #
symbol, if it contains anything at all. You should strip it by adding .substr(1)
:
var test = window.location.hash.substr(1);
$('div').load("test.php?id="+test);
As it is, you are trying to load a url like test.php?id=#22
, and since the hash is meaningless for AJAX purposes, it's being ignored by the .load
method.
Upvotes: 3