Link to home
Start Free TrialLog in
Avatar of swaggerking
swaggerkingFlag for United States of America

asked on

Add querystring to Ajax in classic asp

I have a dynamic page that is displaying details based upon a unique ID being passed in my querystring/url parameter. I'm trying to figure out how to add the querystring to the GET Ajax based upon this unique id.

This what I have:
mypage.asp?id=1

<div id="moreDiv"></div>
<div id="foo">
<h3 class="more"><a href="javascript: void(0)" onclick="toggle_visibility('foo'); loadXMLDoc()"><span>[+]</span> view comments</a></h3>
</div>




<script>
function loadXMLDoc()
{
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }

xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("moreDiv").innerHTML=xmlhttp.responseText;
    }

else {
document.getElementById("moreDiv").innerHTML='<img id="centerload" src="ajax-loader.gif">';
}
}

// I tried this without luck
var myquerystring = window.location.search.substring(1);

xmlhttp.open("GET","commentsmore.asp?id=" + myquerystring,true);
xmlhttp.send();
}
</script>

ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of swaggerking

ASKER

What does "var myquerystring = window.location.search.substring(1);" look like?
My bad. My syntax was wrong. It was displaying "ID=1" instead of what I thought "1".

I changed:
xmlhttp.open("GET","commentsmore.asp?id=" + myquerystring,true);

to
xmlhttp.open("GET","commentsmore.asp?" + myquerystring,true);

and it seems to be working.
Them little things will get you!  Thanks!