Hi, I'm trying something and it only works if i refresh the page, no errors. so i think there is a timing issue, i've been playing with it for a while trying to fix the timing issue with delays here or there but nothing seems to work.
I'm trying to put together a drop box from a remote server based from values from a database on a local server. using ajax to set a variable from ASP (asp calls the db for the values and sets it to a string) then using json to fromulate and display the drop box on the local server
I have a page call test.html (on remote server):
json.js (file resides on local server):
Whats happing in the code is that i'm pulling some info from a db using ajax & asp, i'm returning the asp string (which is actually formatted as html drop box options. Then i'm using the ajax returned variable to create a form element using json and display the json object on a remote server test.html in a form. All is working, no errors or any type, but the drop box does not contain the options from the ajax string until i refresh the page. When i refresh test.html after it loads, the drop box in test.html is populated with the option from ajax/asp. Any thought on how to make this work without refreshing the page once it loads? Thanks
I'm trying to put together a drop box from a remote server based from values from a database on a local server. using ajax to set a variable from ASP (asp calls the db for the values and sets it to a string) then using json to fromulate and display the drop box on the local server
I have a page call test.html (on remote server):
Code:
<html>
<head>
<script src="[URL unfurl="true"]http://www.company.com/json.js"[/URL] type="text/javascript"></script>
<title></title>
</head>
<body>
<script type="text/javascript">
jsonObj.passVar();
//function wait(delay) {
//string="pauseforalert("+delay+");";
//setTimeout(string,delay);
//}
//function pauseforalert(delay) {
//jsonObj.passVar();
//}
//wait(5000);
//alert(a2);
</script>
<h1>hope this works!</h1>
</body>
</html>
json.js (file resides on local server):
Code:
var a1="";
function a12() {
var xmlHttp;
try
{ xmlHttp=new XMLHttpRequest(); }
catch (e)
{ try
{ xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
catch (e)
{ try
{ xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
catch (e)
{ alert("Your browser does not support this search box. Try Firefox, Safari or IE"); return false; } } }
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4) { a1 = xmlHttp.responseText; }
}
xmlHttp.open("GET","default.asp",true);
xmlHttp.send(null);
return a1;
}
jsonObj = {
'formA' : '<select class="frmRateGroup" name="PropertyL" ID="frmRateGroup"><option value="999">All</option>',
'formB' : a12();,
'formC' : '</select>',
'website' : {
'uri' : '[URL unfurl="true"]http://company.com/',[/URL]
'stuff' : {
'CSS' : 'Cascading Style Sheets',
'HTML' : 'HyperText Markup Language',
'JS' : 'JavaScript'
},
'passVar' : function() {
document.write(this.formA + this.formB + this.formC);
}
},
'passVar' : function() {
document.write(this.formA + this.formB + this.formC);
}
};
Whats happing in the code is that i'm pulling some info from a db using ajax & asp, i'm returning the asp string (which is actually formatted as html drop box options. Then i'm using the ajax returned variable to create a form element using json and display the json object on a remote server test.html in a form. All is working, no errors or any type, but the drop box does not contain the options from the ajax string until i refresh the page. When i refresh test.html after it loads, the drop box in test.html is populated with the option from ajax/asp. Any thought on how to make this work without refreshing the page once it loads? Thanks