Solved

Add querystring to Ajax in classic asp

Posted on 2010-09-11
3
719 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 82

Accepted Solution

by:
Dave Baldwin earned 250 total points
Comment Utility
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
Comment Utility
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 82

Expert Comment

by:Dave Baldwin
Comment Utility
Them little things will get you!  Thanks!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
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…

728 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now