Send request to the server but don’t necessarily refresh

Posted on 2003-10-27
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 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:

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
In Angular, how can I programatically fire a function 8 54
reveal text field based on selected 10 24
Angular - break the dataset in chunks? 7 39
Polygon I google maps 1 16
In my daily work (mainly using, I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (, we'll extend the program by adding a depth-…
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…

920 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

16 Experts available now in Live!

Get 1:1 Help Now