Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Send request to the server but don’t necessarily refresh

Posted on 2003-10-27
5
Medium Priority
?
309 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 4

Accepted Solution

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In my daily work (mainly using ASP.net), 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 …
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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…

610 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