Solved

Add querystring to Ajax in classic asp

Posted on 2010-09-11
3
752 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Suggested Solutions

Title # Comments Views Activity
innerHTML 7 34
Code Manager | Snippits 2 36
Insert Button on a table 16 36
IIS 7 and executing pages using localhost 16 12
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

808 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