View Full Version : Dynamically load data from another page
Mhtml
03-30-2003, 02:04 AM
Ok, I was trying to get this script by Vladdy http://www.codingforums.com/showthread.php?s=&threadid=16205&perpage=15 to work but it just doesn't work..
It tells me that script is undefined, and it keeps reporting that there is a syntax error on line 2 char 2.
The script is exactly as is on that thread with nothing of my own in it..
Vladdy
03-30-2003, 03:46 AM
In that thread I just illustraded the concept I've been working on, omitting a few things that were not really relevant. I actually typed the post in MS Word, so if you did not replace the Word weird quotes after copying the code, there is one possible source of error.
In any case here is the tested code ready for cut and paste:
client.html:
<html>
<head>
<title>Background Server Poll Demo</title>
<script>
var script = null;
function pollServer(query)
{ if(script) return false; //Do not send new request while
//there is one being processed
script = document.createElement('script');
script.src = 'server.asp?' + query;
script.type = 'text/javascript';
document.getElementsByTagName('head')[0].appendChild(script);
return false;
}
function processServerResponse(data)
{ alert('Server returned: ' + data);
setTimeout('requestProcessed()',50);
return;
}
function requestProcessed()
{ document.getElementsByTagName('head')[0].removeChild(script);
script = null;
return;
}
</script>
</head>
<body>
<a href="#" onclick="return pollServer('get=info1');">Get info 1</a>
<a href="#" onclick="return pollServer('get=info2');">Get info 2</a>
</body>
</html>
server.asp
<%@ Language =JScript EnableSessionState = False%>
<%
Response.Buffer = true;
Response.ContentType = 'text/JavaScript';
// Just threw in everything I heard about preventing
// the page from being cached.
Response.Expires = 0;
Response.ExpiresAbsolute = '01/01/1999';
Response.AddHeader ('pragma','no-cache');
Response.AddHeader ('cache-control','private');
Response.CacheControl = 'no-cache';
var ReturnedData = '';
Action = Request.QueryString('get');
if(Action == 'info1') ReturnedData = 'Returned info1 data';
if(Action == 'info2') ReturnedData = 'Returned info2 data';
%>
processServerResponse('<%=ReturnedData%>');
Just a reminder about the obvious fact that you need to use http protocol since asp script would not be executed if you use file:// (after double-clicking on the file name)
Mhtml
03-30-2003, 04:14 AM
Schweeeet..... :D
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.