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

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
ayudhAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Michel PlungjanConnect With a Mentor IT ExpertCommented:
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
 
CJ_SCommented:
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
 
ayudhAuthor Commented:
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
ayudhAuthor Commented:
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
 
CJ_SCommented:
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
 
Chandramouli kArchitectCommented:
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
 
CJ_SCommented:
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
 
ayudhAuthor Commented:
I just tested your suggestion - it works exactly like I wanted. Thank you.
0
All Courses

From novice to tech pro — start learning today.