Solved

Is it possible to reload an included javascript file without reloading the page?

Posted on 2002-06-02
8
395 Views
Last Modified: 2013-11-18
Can I force a refresh of an included javascript file without reloading the page itself (like you can do with image)? I am using the "Javascript Syndication" method of pulling data from another server. The javascript file contains a bunch of variables provided by the server script which I can use to populate form fields on the page. Works fine when the page is initially loaded, but would like it to be more dynamic. Here's what I'm trying to do:

A user fills in an email field. I would like to put an onChange trigger on the field which forces a refresh of the javascript file. The user's email address is appended as a query string to the URL. The server uses this value to look up a database and return the user details as a series of javascript name-value pairs in the reloaded file. I can then use these values to populate the rest of the form. All without refreshing the page.

Regards: Ayudh
0
Comment
Question by:ayudh
8 Comments
 
LVL 22

Expert Comment

by:CJ_S
Comment Utility
What you can do is create a hidden frame which does the actual reloading.

With other words:
- create another frame which is hidden to the end-user, call the frame frHidden.
- use the following code to load the js file:
var sHTML="<html><head><scri"+"pt language='javascript' src='myjs?myemail'></sc"+"ript></head></html>"
parent.frHidden.document.write(sHTML);
parent.frHidden.document.close();

Now you can access those variables using the following:
parent.frHidden.MyVariable;

CJ
0
 

Author Comment

by:ayudh
Comment Utility
Thanks CJ_S
Is it possible to reload just the JS file without introducing frames?
Also, any reason why in your example above you break up the HTML string into 3 parts at those particular points and concatenate them together? Since the email address in the query string is the variable, I would have thought it should read thus:
var sHTML="<html><head><script language='javascript' src='myjs?" + myemail + "'></script></head></html>"

Regards: Ayudh
0
 

Author Comment

by:ayudh
Comment Utility
Thanks CJ_S
Is it possible to reload just the JS file without introducing frames?
Also, any reason why in your example above you break up the HTML string into 3 parts at those particular points and concatenate them together? Since the email address in the query string is the variable, I would have thought it should read thus:
var sHTML="<html><head><script language='javascript' src='myjs?" + myemail + "'></script></head></html>"

Regards: Ayudh
0
 
LVL 22

Expert Comment

by:CJ_S
Comment Utility
You can only write out script tags when you break them apart, otherwise several browsers won't do what you want it to do.

You cannot reload javascript without frames if you need those variables. Otherwise I would suggest using XML instead. But that wouldn't be browser compatible at all.

Above is the best thing you can get. If you want it to be without a frameset you'd have to create an iframe (can be hidden also) and use that to collect the javascript.

CJ
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 100 total points
Comment Utility
IE allows
<script ID="myScript" src="someserverprocess?email=default"></script>

document.all('myScript').src='someserverprocess?email='+escape(emailVar);

Perhaps NS6 too:

document.getElementById('myScript').src='someserverprocess?email='+escape(emailVar);


Michel
0
 
LVL 5

Expert Comment

by:kcm76
Comment Utility
CJ

**What you can do is create a hidden frame which does the actual reloading

var sHTML="<html><head><scri"+"pt language='javascript' src='myjs?myemail'></sc"+"ript></head></html>"
parent.frHidden.document.write(sHTML);
parent.frHidden.document.close();**

i dont understand how does a frame reload a .js file. Could u pls explain me in detail. I cant understand anything from it. Did I/U miss anything?

KCM
0
 
LVL 22

Expert Comment

by:CJ_S
Comment Utility
It loads a js file, it does not reload the js file. In fact, it works just like a normal html page which loads an js file.

CJ
0
 

Author Comment

by:ayudh
Comment Utility
I just tested your suggestion - it works exactly like I wanted. Thank you.
0

Featured Post

Highfive Gives IT Their Time Back

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

Suggested Solutions

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

743 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