Send request to the server but don’t necessarily refresh

Posted on 2003-10-27
Medium Priority
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.

Question by:CodeMachine

Accepted Solution

mrmcfeely earned 500 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:

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.
LVL 12

Expert Comment

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:

So it would be like:
setTimeout("checkIt()", 15000);
function checkIt() {
  var script=document.createElement("script");
  if (document.getElementById("checker") {
LVL 25

Expert Comment

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.

Author Comment

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

Author Comment

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:)


Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…
Suggested Courses

579 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