?
Solved

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

Posted on 2002-06-02
8
Medium Priority
?
407 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
[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
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
Independent Software Vendors: 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

Independent Software Vendors: 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

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

718 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