Solved

Send request to the server but don’t necessarily refresh

Posted on 2003-10-27
5
287 Views
Last Modified: 2011-10-03
I have a general question about the feasiblity of this scenario.

I would like to write some javascript to poll my server from my web page.

Basicly i would like to make a request to the server as you would with a submit button. but i only want the page to refresh if  logic that resides on the server indicates that it is approprate to do so.

I have no solid constraints on how to do this and any suggestions would fall on gracious ears.
want More background?

I have a page with a list of tasks i want to check the server for new tasks say every 15 seconds but i dont want the page always refreshing.

0
Comment
Question by:CodeMachine
5 Comments
 
LVL 4

Accepted Solution

by:
mrmcfeely earned 125 total points
ID: 9629891
If have the luxury of making it an "IE only" web page, you could leverage the MSXML object to make synchronous HTTP requests through jscript (without performing any page navigations).

Check out this site, which has an example:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/htm/dom_howdoi_21id.asp

Once the content returns, you can parse through it and see if there's a new task... if you make your page with the list of tasks return a well-formed XML document, this solution becomes even easier!


Another option would be to load the tasks page into a hidden IFRAME on the main page, and then parse through the IFRAME's contents using the innerHTML property.  This would effectively keep the main page from refreshing.  There are a couple caveats, though... one, you'd have to write some code to detect when the content in the IFRAME has fully loaded... two, you're subject to cross-domain scripting restrictions (meaning that the innerHTML property is unavailable to you if the page being loaded into the IFRAME is not in the same exact domain as the main page).


These suggestions are admittedly somewhat vague, but they're a couple ideas to get your mind moving.  Let me know if you'd like me to elaborate more on either one of these suggestions.
0
 
LVL 12

Expert Comment

by:ahosang
ID: 9630140
A solution is to create new <script> tag and set the source to your server-side page. Then in that logic, if the update is needed, then make the server page send a script that says:
location.reload(true);

So it would be like:
<script>
setTimeout("checkIt()", 15000);
function checkIt() {
  var script=document.createElement("script");
  script.src="checkpage.jsp";
  script.id="checker";
  if (document.getElementById("checker") {
    document.removeChild(document.getElementById("checker"));
  }
  document.getElementsByTagName("head")[0].appendChild(script);
}
</script>
0
 
LVL 25

Expert Comment

by:devic
ID: 9630171
sumit target on hidden iframe.
hidden iframe has event onload.
onload read what send the server.
if server want reload all the page, reload it.
0
 

Author Comment

by:CodeMachine
ID: 9672397
Hey thatnks for all yer comments you guys... I sure appreciate it. Dunno who to give th points to. I will have to see what i am gonna implement... Getting to it.

I will let you know
0
 

Author Comment

by:CodeMachine
ID: 9676621
Thanks once again to all. Ah the nuances of web programming.

After some research the iframe should provide the functionality i require... with a little work i should have a solution without to much hassle:)

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
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…

705 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

15 Experts available now in Live!

Get 1:1 Help Now