I have AJAX (I think) returning data from a server call.
function showCustomer(str) {
var xmlhttp;
if (str=="") {
document.getElementById("txtHint").innerHTML="";
return;
}
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("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET", "getcustomer3.asp?q=" + str, true);
xmlhttp.send();
}
The call returns this:
<script>var CC2=101;var CC4=105;</script>
The 101 & 105 are data from my DB.
I have a function in the page that the data is returned to. This is the function:
function unhideCC() {
$("#" + CC2).show();
$("#" + CC4).show();
}
I am calling the function from a button onClick event, and I wait to click said button until after the data has been returned, which I thought would work.
I am struggling to get the variables written back to the page to load into the function. I have a strong feeling I'm going about this in the entirely wrong way. Any pointers to get me on the correct path?
Thanks ahead of time!
EDIT: This is the code that returns the values:
response.write("<script>")
dim counter: counter = 0
do until rs.EOF
for each x in rs.Fields
counter = counter + 1
'Use Mod() to check counter is even
If counter Mod 2 = 0 Then response.write "var CC" & counter & "=" & x.value & ";"
next
rs.MoveNext
loop
response.write("")
response.write("</script>")
unhideCC()at any point...?