Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2002-06-02
8
Medium Priority
?
416 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
ID: 7049571
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
ID: 7050191
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
ID: 7050225
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
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!

 
LVL 22

Expert Comment

by:CJ_S
ID: 7050573
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
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 400 total points
ID: 7050586
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
ID: 7050728
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
ID: 7050765
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
ID: 7050770
I just tested your suggestion - it works exactly like I wanted. Thank you.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Suggested Courses

926 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