Solved

Add querystring to Ajax in classic asp

Posted on 2010-09-11
3
762 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
  • 2
3 Comments
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 250 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

jQuery is a JavaScript library that greatly simplifies JavaScript programming. AJAX is an acronym formed from "Asynchronous JavaScript and XML."  AJAX refers to any communication between client and server, when the human client does not observe a…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

756 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