|
Subject:
|
update using Asp and jscript
|
|
Posted By:
|
alyeng2000
|
Post Date:
|
11/5/2003 7:35:42 PM
|
hi all, i need to update part of the page with the Information in the Application object every certain amount of time, all what i do that i use SetInterval(func,period) to synchronize the execution of this function, in this function i update the element in the page using InnerHtml attribute, this is a part of the code
function fnStartInterval(){ oInterval=window.setInterval("fnRecycle()",4000); }
function fnRecycle(){ var htmlText htmlText="" htmlText="<%for i=Application("msgno")+1 to 10 response.write "<span STYLE='color:" & clrs((i mod 10)+1) & "'>" & application("msg" & i ) & "</span><br>" next
for i=1 to Application("msgno") response.write "<span STYLE='color:" & clrs((i mod 10)+1) & "'>" & application("msg" & i ) & "</span><br>" next %>"; //alert(htmlText); update("writemsg",htmlText); }
function update(id, html) { document.all[id].innerHTML = html;
}
but i notice that the html text generated from ASP code is the same as it's reference the server once, all i need is to reference the server for each hit to the function called in SetInterval,
If Any one have Solution plz help
Ahmed Ali Software Developer
|
|
Reply By:
|
planoie
|
Reply Date:
|
11/6/2003 11:25:15 AM
|
Take a look at your source HTML when this page is generated.
You'll notice that the values that you retrieved in ASP that you write out to the javascript block are static:
htmlText="<here is where the static text will be, instead of the asp code"
This is because the ASP is running on the server and only get's called once, when the page is first requested. You are having the client browser call fnRecycle at timed intervals, but the end result is always the same because it's only run at the server once.
The simplest way to do what you are trying is to set a auto refresh header on the page so the browser refreshes the page at timed intervals (and thus getting an updated version from the server).
If you only want to update a small part of the page and you need it to be that way, then you'll have to do something much more complicated.
One simple alternative (affected by what browsers you plan on supporting) is to use an iframe. This can contain a very simple page with just the contents that you want to have updated. That page can refresh to it's hearts delight, but the main page it lives in will stay the way it is without refreshing.
Peter ------------------------------------------------------ Work smarter, not harder.
|
|
Reply By:
|
alyeng2000
|
Reply Date:
|
11/6/2003 5:27:37 PM
|
thanks peter for your detail solution,
i know some about iframe idea but i am asking i will then retrieve this part of asp code in request object, if you please give me sample code for this IFRAME Solution(how to use iframe).
Ahmed Ali Software Developer
|
|
Reply By:
|
planoie
|
Reply Date:
|
11/6/2003 7:24:32 PM
|
For either solution I suggested, you simply need to set the page to refresh after some time period. When it refreshes, it will update with the new information from the application object. You need to write out a meta refresh tag to the HTML so the browser will refresh the page.
The idea behind of the iframe is simply to minimize how much of the page you have to refresh. If you only really want to refresh a small piece, and you can use the iframe, then you just create a page with only the information that needs to be refreshed. You write this page out with refresh meta tag so it will refresh periodically in the iframe (versus the whole page in the browser refreshing).
Peter ------------------------------------------------------ Work smarter, not harder.
|
|
Reply By:
|
alyeng2000
|
Reply Date:
|
11/6/2003 7:48:34 PM
|
thx planoie, i use iframe and i periodically assign the src attribute for the iframe as ASP page but error is produced as the debugger stop on the first line of the asp page !!!
what i have to do????
fnRecycle is the periodic function set with setinterval
function fnRecycle(){ document.frames("updframe").src="MsgContent.asp" }
this the file MsgContent.asp
<% for i=Application("msgno")+1 to 10 response.write "<span STYLE='color:" & clrs((i mod 10)+1) & "'>" & application("msg" & i ) & "</span><br>" next
for i=1 to Application("msgno") response.write "<span STYLE='color:" & clrs((i mod 10)+1) & "'>" & application("msg" & i ) & "</span><br>" next %>
Ahmed Ali Software Developer
|
|
Reply By:
|
planoie
|
Reply Date:
|
11/7/2003 9:34:27 AM
|
What's the error you are getting?
Peter ------------------------------------------------------ Work smarter, not harder.
|
|
Reply By:
|
alyeng2000
|
Reply Date:
|
11/8/2003 11:06:01 PM
|
thanks planoie, i have found the error it was undeclard variable, but i Know now how to use iframe,the problem remains i need to recieve data, where to get this returned data got from server, thats what i need help now ...like request("varname") recieved to iframe ??? how could i do that, .
Ahmed Ali Software Developer
|
|
Reply By:
|
planoie
|
Reply Date:
|
11/10/2003 11:03:53 AM
|
I'm not sure I understand what you are trying to do now. I thought all you wanted was to be able to update a section of the page at timed intervals. It seems you have gotten this part figured out.
Is there more? It sounds like you now want to do something with the actual output of the data in the IFrame. Do I understand your intention correctly?
Peter ------------------------------------------------------ Work smarter, not harder.
|
|
Reply By:
|
alyeng2000
|
Reply Date:
|
11/10/2003 11:11:37 PM
|
ok to clear what i mean, i saw in the site http://www.theill.com/ a free code for asp chat and i saw that the asp page is working so smooth with out any refreshing the user could feel, so i was trying to understand this way,
if any could help.
Ahmed Ali Software Developer
|
|
Reply By:
|
planoie
|
Reply Date:
|
11/11/2003 9:47:12 AM
|
Ok. I see what you are looking for now.
What is being used for ConquerChat is a whole different scenario. Well, not THAT different. That is all frames based. There are five different frames in that application, each pointing to a different page. They each run independently, although they do interact with each other to tell each other to refresh when something happens (like you enter a message).
All the data that shows up in each window (list of users, messages, etc) comes from objects that are stored in the Application object of ASP. It looks to me like the only frame-to-frame interaction is just one frame telling another to refresh.
Peter ------------------------------------------------------ Work smarter, not harder.
|
|
Reply By:
|
alyeng2000
|
Reply Date:
|
11/11/2003 4:06:12 PM
|
thanks planoie for sharing
the idea is still not cleared(smooth refreshing ) did you see the file update.js i think there is a functions that is stange to me,it's used for updating frames.....
the smooth refresh in previous mentioned site(conqurechat) is the new difference from all simple chat scripts which use traditional <META HTTP-EQUIV='Refresh' CONTENT='10; URL=file.asp'> to refresh page..
all i need is some clear view for that script (i am not so good at jscript)
Ahmed Ali Software Developer
|
|
Reply By:
|
planoie
|
Reply Date:
|
11/12/2003 12:30:27 PM
|
What do you mean when you say "smooth refresh"? The smoothness of a page refresh mostly depends on how the browser renders a page. Changing the way it refreshes isn't going to help. Refresh is refresh. I'll bet if you dug down enough into that code that you'd see there are just meta tag refreshes and javascript refresh calls in it. Nothing more complicated than that.
Peter ------------------------------------------------------ Work smarter, not harder.
|
|
Reply By:
|
alyeng2000
|
Reply Date:
|
11/13/2003 8:38:39 PM
|
thanks planoie for your patience keep replying to me
below is that jscript code (which i think update functions used)
he also call Refresh function as.. executeRequest('action=refresh');
<!-- var SERVER_CONTROLLER = "control.asp"; /** * Executes a server request by patching the header request in the * current document. The parameters specified will be attached to * the request. * */ function executeRequest(params) { var head = document.getElementsByTagName('head').item(0); var old = document.getElementById('lastLoadedCmds'); if (old) head.removeChild(old); script = document.createElement('script'); parameters = new String(params).split(','); var scriptUrl = SERVER_CONTROLLER + '?rnd=' + Math.random(); for (var i = 0; i < parameters.length; i++) { scriptUrl += "&" + parameters[i]; } script.src = scriptUrl; script.type = 'text/javascript'; script.defer = true; script.id = 'lastLoadedCmds'; void(head.appendChild(script)); } // > function executeRequest(...) /** * Dynamically updates the content of a frame. * */ function update(frame, id, html) { var doc = eval(frame + '.document'); if (doc.layers) { var l = doc[id]; l.document.open(); l.document.write(html); l.document.close(); } else if (doc.all && doc.all[id]) { doc.all[id].innerHTML = html; } else if (doc.createRange) { var l = doc.getElementById(id); var r = doc.createRange(); while (l.hasChildNodes()) { l.removeChild(l.lastChild); } r.setStartAfter(l); var docFrag = r.createContextualFragment(html); l.appendChild(docFrag); } } // > function update(...) function updateMessages(id, html) { update('parent.messages', id, html); } function updatePrivateMessages(id, html) { update('parent.messages', id, html); } function updateUsers(id, html) { update('parent.users', id, html); onUsersChanged(undefined); } function updateRooms(id, html) { update('parent.rooms', id, html); } function onUsersChanged(data) { if (typeof data == 'undefined') return; if ((typeof parent.message != 'undefined') && (typeof parent.message.onUsersChanged != 'undefined')) parent.message.onUsersChanged(data); } function focusMessageArea() { if ((typeof parent.message != 'undefined') && (typeof parent.message.frmControl != 'undefined') && (typeof parent.message.frmControl.message != 'undefined')) { parent.message.focus(); parent.message.frmControl.message.focus(); } } function scrollToBottom(bottom) { var doc = parent.messages.document; var wnd = parent.messages; var y = doc.height ? doc.height : doc.body.scrollHeight; //alert(doc.height + ",bottom="+bottom+",y="+y); wnd.scrollTo( 0, ((bottom == 'true') ? y : 0) ); } // > function scrollToBottom(...)
Ahmed Ali Software Developer
|