Hi,
I have a file containing variables defined in javascript syntax, like,
var a = 15;
var list = [ 'a','b','c'];
..
..
I want to load this external file dynamically and read in the data.
I can successfuly read this file content if I include the file
statically in the head section in my page. But when I am trying to
include the file using DHTML, i cannot source it.
Please suggest.
Regards,
Suvajit 6 7060
jeet_sen said the following on 3/7/2006 10:58 PM: Hi, I have a file containing variables defined in javascript syntax, like, var a = 15; var list = [ 'a','b','c']; .. .. I want to load this external file dynamically and read in the data. I can successfuly read this file content if I include the file statically in the head section in my page. But when I am trying to include the file using DHTML, i cannot source it. Please suggest.
Show some source code on how you are loading it and attempting to access it.
--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
I am loading the data with the following function:
function loadScript (url, id, callback) {
var scriptElement = document.create Element('script ');
scriptElement.t ype = 'text/javascript';
scriptElement.s rc = url;
scriptElement.i d = id;
if (typeof scriptElement.a ddEventListener != 'undefined') {
scriptElement.a ddEventListener (
'load',
function (evt) { callback(); },
false
);
}
else if (typeof scriptElement.a ttachEvent != 'undefined') {
scriptElement.a ttachEvent(
'onreadystatech ange',
function () {
if (scriptElement. readyState == 'complete') {
callback();
}
}
);
}
document.getEle mentsByTagName( 'head')[0].appendChild(sc riptElement);
}
Function call:
// Load data
file2Load = 'test.js';
loadScript(file 2Load,name,func tion () { alert(file2Load +"
loaded!!");} );
test.js looks like this:
var TABLE_ITEMS = {
'name' : 'GS60H',
'level' : 'Library',
'child' : {
'gs60hcustom' : {
'qualis'
: {'status' : 'PASSED' },
'startAttribute Check'
: {'status' : 'WAIVED' },
'availabilityCh eck'
: {'status' : 'PASSED' },
'libAttributesC heck'
: {'status' : 'PASSED' },
'checkViewConsi stency' : {'status' : 'PASSED' },
'simModelsCompi le'
: {'status' : 'FAILED' },
},
},
'total' : 500,
'failed' : 20,
'waive' : 5
};
* Used callback to ensure that my script loading function is working
properly.
Found that the passed function has been called and new script tag
has been created successfully.
* But I cannot access the object TABLE_ITEMS defined in test.js. What
is the scope of the object loaded through a script dynamically?
jeet_sen wrote: I am loading the data with the following function:
The function is fine, your data file has syntax errors.
function loadScript (url, id, callback) { var scriptElement = document.create Element('script '); scriptElement.t ype = 'text/javascript'; scriptElement.s rc = url; scriptElement.i d = id; if (typeof scriptElement.a ddEventListener != 'undefined') { scriptElement.a ddEventListener ( 'load', function (evt) { callback(); }, false ); } else if (typeof scriptElement.a ttachEvent != 'undefined') { scriptElement.a ttachEvent( 'onreadystatech ange', function () { if (scriptElement. readyState == 'complete') { callback(); } } ); } document.getEle mentsByTagName( 'head')[0].appendChild(sc riptElement);
}
Function call: // Load data file2Load = 'test.js'; loadScript(file 2Load,name,func tion () { alert(file2Load +" loaded!!");} );
There is a syntax error here from auto-wrapping. When posting code,
manually wrap at about 70 characters so it can be quoted a couple of
times without wrapping.
var file2Load = 'test.js';
loadScript(file 2Load,name,func tion () {
alert(file2Load + " loaded!!");
// Test availability of TABLE_ITEMS
alert(TABLE_ITE MS.name);
} );
But that's not the really problem... test.js looks like this:
var TABLE_ITEMS = { 'name' : 'GS60H', 'level' : 'Library', 'child' : { 'gs60hcustom' : { 'qualis' : {'status' : 'PASSED' }, 'startAttribute Check' : {'status' : 'WAIVED' }, 'availabilityCh eck' : {'status' : 'PASSED' }, 'libAttributesC heck' : {'status' : 'PASSED' },
--------------------------^^^
the extra comma here causes problems. 'checkViewConsi stency' : {'status' : 'PASSED' }, 'simModelsCompi le' : {'status' : 'FAILED' }, },
---------------------------------------------------^^^
As does this one. Formatting for posting would have helped. Firefox
was happy with it (surprisingly), only IE barfed for me.
}, 'total' : 500, 'failed' : 20, 'waive' : 5 };
It's probably better to use machine-generation of such code, it's very
fussy doing it manually. Try building a form that generates the code in
a text area for copy/paste (for your local use only of course).
Try this version:
var TABLE_ITEMS = {
'name' : 'GS60H',
'level' : 'Library',
'child' : {
'gs60hcustom' : {
'qualis' : {'status' : 'PASSED' },
'startAttribute Check' : {'status' : 'WAIVED' },
'availabilityCh eck' : {'status' : 'PASSED' },
'libAttributesC heck' : {'status' : 'PASSED' },
'checkViewConsi stency': {'status' : 'PASSED' },
'simModelsCompi le' : {'status' : 'FAILED' }
}
},
'total' : 500,
'failed' : 20,
'waive' : 5
};
--
Rob
Hi Rob,
Thanks a lot for your effort and time. I will surely try it out.
My data files will be machine generated. I generated the file manually
just to implement my plan.
Lately I have worked on an alternative plan and have implemented it.
Instead of the object literal form I dumped my data in XML form and it
is working fine.
Please suggest what will be a better option.
Regards,
Suvajit
jeet_sen wrote: Hi Rob, Thanks a lot for your effort and time. I will surely try it out. My data files will be machine generated. I generated the file manually just to implement my plan. Lately I have worked on an alternative plan and have implemented it. Instead of the object literal form I dumped my data in XML form and it is working fine. Please suggest what will be a better option.
I can't tell you which is better - have a look at JSON:
<URL:http://www.json.org/>
--
Rob
RobG wrote: jeet_sen wrote: var TABLE_ITEMS = { 'name' : 'GS60H', 'level' : 'Library', 'child' : { 'gs60hcustom' : { 'qualis' : {'status' : 'PASSED' }, 'startAttribute Check' : {'status' : 'WAIVED' }, 'availabilityCh eck' : {'status' : 'PASSED' }, 'libAttributesC heck' : {'status' : 'PASSED' }, --------------------------^^^
the extra comma here causes problems.
'checkViewConsi stency' : {'status' : 'PASSED' }, 'simModelsCompi le' : {'status' : 'FAILED' }, },
---------------------------------------------------^^^
As does this one. Formatting for posting would have helped. Firefox was happy with it (surprisingly), only IE barfed for me.
It is not surprising to me, because JavaScript is known
to work as specified in ECMAScript here; JScript does not.
PointedEars This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: jason baumunk |
last post by:
I author applications in php which use external stylesheets. When
viewed through ie 6, netscape 6, et al. occassionally the stylesheets
will not load or be applied. Has anybody encountered this and found a
fix/workaround so that the stylesheets are verified as having been
loaded/applied? I'm running apache and the external stylesheets are
actually php files that serve dynamic stylesheets(ie,
site.css.php......I don't suspect that this...
|
by: Ray in HK |
last post by:
What are the differences between LOAD DATA INFILE and LOAD DATA LOCAL INFILE
?
I found some web hosting company do not allow using LOAD DATA INFILE but
allow LOAD DATA LOCAL INFILE. The reason is for the sake of security. What
does that mean ?
|
by: jay |
last post by:
hi,
Question on Load/import command.
consider a sample table
create table table_name (
col1 timestamp not null default current timestamp,
col2 int,
col3 int,
col4 int,
primary key(col1) );
There is a file file.del containing data for col2,col3,col4. Data for
|
by: GeekBoy |
last post by:
Okay, I have two identical web servers running Windows 2003 web
server. I have an ASP.NET application which runs great on one of
them. Dedicated IP address, behind our firewall, etc. Everyone's
happy.
Now -- how do I take advantage of that second computer to
"load-balance" the web site? Will it really give my users a noticable
performance increase? How do you accomplish this? I've read many of
those MS articles and it's...
|
by: eieiohh |
last post by:
MySQL 3.23.49
PHP 4.3.8
Apache 2.0.51
Hi All!
Newbie..
I had a CRM Open Source application installed and running. Windows Xp
crashed. I was able to copy the contents of the entire hard drive onto
a USB External Hard Drive. I have to assume I also copied the data. I
| |
by: Magnus |
last post by:
I'm currently developing an application with classified information as
input to a couple of algorithms.
Which strategy should I use to protect the input data from beeing read?
The files should be files on the local computer in the application
directory structure and it must be possible to update the input data
with an external application.
My current approach is to deserialize the input data in the "external
application" and then...
|
by: Jeff Allan |
last post by:
Hello,
I am trying to load an external HTML page into a DIV tag with .NET 05 and I
can't figure it out. Any suggestions?
My Scenario:
- Gridview populated with list of available files
- I can get the external page to load in a new window just fine
- I would like the detail to show on the same page, below the list.
- I can't use the detail control and dynamically create the page as these
|
by: John Dunn |
last post by:
Since currently we aren't allowed to have compiled XAML files embedded in C++
apps I'm using Markup::XamlReader::Load to dynamically load XAML files. This
works perfectly fine with external files but I'd like to be able to load a file
specified in a .resx resource.
I've added my .xaml file to the .resx and can load it in using
ResourceManager::GetObject(). The object returned is a System::Array^ which
contains System::Byte objects. The...
|
by: f rom |
last post by:
----- Forwarded Message ----
From: Josiah Carlson <jcarlson@uci.edu>
To: f rom <etaoinbe@yahoo.com>; wxpython-users@lists.wxwidgets.org
Sent: Monday, December 4, 2006 10:03:28 PM
Subject: Re: 1>make_buildinfo.obj : error LNK2019: unresolved external symbol __imp__RegQueryValueExA@24 referenced in function _make_buildinfo2
Ask on python-list@python.org .
- Josiah
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |