</div>
</div>
<div class="grid--cell mb0 mt8">Closed <span title="2012-11-30 07:47:47Z" class="relativetime">7 years ago</span>.</div>
</div>
</aside>
Possible Duplicate:
How can I get query string values?
Hello I have a page with a url like
mypage.com?iid=11&pid=1
In there im running some ajax and need to pass the idd from my querystring to this code block
$.ajax({
dataType : "html" ,
url: "stream.php?iid=[GET iid]&lastComment="+ $(".postedComment:last").attr('id') ,
But am not experienced enough with JS to get my syntax correct. What would i use in place of [GET iid] to pass that variable?
<?php $_GET['iid'];?>
won't work since its a JS file.
Thanks
</div>
There is no standard solution. Everyone has his own solution.
Personally I sometimes use this function :
getUrlParameter = function(name, defaultValue) {
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var results = new RegExp( "[\\?&]"+name+"=([^&#]*)" )
.exec( document.location.href );
if( results == null ) return defaultValue;
else return decodeURIComponent(results[1]);
};
like this :
$.ajax({
dataType : "html" ,
url: "stream.php?iid="+getUrlParameter('iid')+"&lastComment="+ $(".postedComment:last").attr('id') ,
Here is the answer
How can I get query string values in JavaScript?
function getParameterByName(name)
{
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + name + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.search);
if(results == null)
return "";
else
return decodeURIComponent(results[1].replace(/\+/g, " "));
}