?
Solved

Add querystring to Ajax in classic asp

Posted on 2010-09-11
3
Medium Priority
?
773 Views
Last Modified: 2012-05-10
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>

0
Comment
Question by:swaggerking
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 1000 total points
ID: 33654433
What does "var myquerystring = window.location.search.substring(1);" look like?  You may have to URL encode it.  This page shows how: http://www.javascriptkit.com/dhtmltutors/ajaxgetpost.shtml
0
 

Author Comment

by:swaggerking
ID: 33654529
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.
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 33654634
Them little things will get you!  Thanks!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question