Hello.
I have always thought that the eval() function was very flexible and
useful. If I use it, I can define functions at runtime!!
However, I have found a case where eval() does not work properly. It
works, for example, when invoking functions (alert('hello') ), but not
for defining functions.
The case occurs when retrieving the javascript code with
XMLHttpRequest( ). It fails on Mozilla/Firefox and IE!
I will quote the code:
<script>
function RequestDocument (sURL, bAsync) {
var oXmlRequest;
/* branch for native XMLHttpRequest object */
if (window.XMLHttp Request) {
oXmlRequest = new XMLHttpRequest( );
oXmlRequest.ope n("GET", sURL, bAsync);
oXmlRequest.sen d(null);
}
/* branch for IE/Windows ActiveX version */
else if (window.ActiveX Object) {
oXmlRequest = new ActiveXObject(" Microsoft.XMLHT TP");
oXmlRequest.ope n("GET", sURL, bAsync);
oXmlRequest.sen d();
}
return oXmlRequest;
}
function EvalScriptFile( oDocument){
if (oDocument){
/* only if status shows "loaded" */
if (oDocument.read yState == 4) {
/* only if "OK" */
if (oDocument.stat us == 200) {
eval(oDocument. responseText);
}
else if (oDocument.stat us == 404) {
alert("File not found");
}
}
}
}
function LoadScriptFile( sURL){
var oScriptFileRequ est = RequestDocument (sURL,false);
EvalScriptFile( oScriptFileRequ est);
}
//this works:
eval("alert('he llo');function test(){ alert('test'); };");
test();
//but, if I put on a file (called mylib.js and located at the same
//dir as this file on the web server), the following contents:
// alert('hello2') ;
// function test2(){ alert('test2'); };
//
LoadScriptFile( "mylib.js") ;
test2();
//the first alert is called (hello2)! but debugger says
//that test2 is not defined!
// what happens??
</script>
Do anybody know why?? Thanks in advance.
Regards,
Andrew
--
Jul 23 '05
12 3443
Razzbar escribió: So shall also be many users scratching their heads as their browsers hang useless, because some cowboy figured that if you put your JS functions on the server and use a synchronous call, you are guaranteed they will come a'running ever time, and execute when you want them to, not before.
If JS don't work, my sites fallback to the fact that they don't support
client-side scripting, then many browsers will be supported only because
of this.
Regards,
knocte
--
VK escribió: The case occurs when retrieving the javascript code with XMLHttpReques t(). It fails on Mozilla/Firefox and IE!
Actually XMLHTTP doesn't stay from "get XML or HTTP or whatever you'll get in your head". It stays from "get XML data for HTML environment (browser)". But I'm affraid that all hell broke loose already. Mr. Knocte is getting his JavaScript this way, someone already tried to get binary data stream. So soon I guess we'll see XMLHTTP used to download music, pictures and "Star Wars Episode 3". So shall be it...
Actually, I think the feature should be just called "HttpReques t",
because nothing prevents me for getting anything I want with the Http
protocol using this.
Regards,
knocte
P.S.: Perhaps you should suggest to the responsible for DOM specs to
delete the accessibility to the ".responseT ext" attribute. That way
you'll be able to dictate how the technologies must be used.
--
> Actually, I think the feature should be just called "HttpReques t", because nothing prevents me for getting anything I want with the Http protocol using this.
"Who can stop Hafiz from likening a ladybug to the Padishah"
An old Persian proverbe ;-)
<http://groups-beta.google.com/group/comp.lang.javas cript/browse_frm/thread/f6ce0a5e95d8bf3 0/ba5264709e33894 e?q=group:comp. lang.javascript +author:VK&rnum =19&hl=en#ba526 4709e33894e> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: vanisathish |
last post by:
Hi
I am running a client side javascript timer to periodically refresh the
contents of some tables in the HTML page. The table values are
dynmically binded from XML DOM object using the <XML tag in HTML>. The
data is getting updated properly. but whenever the value is refreshed,
the HTML page flickers. How do i avoid this flickering..
below is my html page
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
by: Jason Shohet |
last post by:
I want to build a rules engine in a rules.xml page. I was thinking it
would look like this:
- Rules
- rule1 if (0 < iTime <= .5) { iFee = 15; }
- rule2 if (.5 < iTime <= 1) { iFee = 20; }
- yada yada
Now lets say in my c# code I loop thru the Rules node of rules.xml, and I
want to evaluate each rule, given an iTime that the user inputed -- lets
|
by: Hitesh |
last post by:
Hi,
I am getting the response from another Website by using the HttpHandler in
my current site. I am getting the page but all the images on that page are
not appearing only placeholder are displayed.
Can anybody know this issue and help me to resolve this.
In past i received the response saying that i should download the image
first and then parse the actual response and modify the src attribute of the
|
by: Larry |
last post by:
Hi there:
I have seen numerous postings about eval() and its evils on this forum.
However, one of our developers is using it in the following way,
which seems like a great use of it.
Page makes Ajax request to ASP.Net web service. Web service does some
data lookup and builds a string representation of a Javascript array
which is then returned to the client. In the ajax callback, call to
eval on the returned string and voila, ...
|
by: |
last post by:
I have what's probably a simple page lifecycle question related to
dynamically evaluating values that are placed by a repeater and dynmically
placing user controls that use those values.
I'm attempting to bind a user control I've written, "ImageBox", to a
repeater.
The user control takes a custom property, "ContentID", that will execute a
database lookup and load an image.
| |
by: Pablo |
last post by:
Dear all,
I have a website where I need to fill its contents after retrieving
some data from another system (not a DB, but you can think like it).
I know the nature of the data, but the order that it is retrieved is
random, and there is no way to order it. Therefore, it is giving me
some pain to produce the html code.
I was thinking of having the following javascript to place my html
code. Here, "rightImg" is the ID of a DIV tag where I...
|
by: Tarik Monem |
last post by:
OK, I'm pretty sure this cannot work because I'm trying to use JavaScript (client-side) to write to an xml file (which is server-side) using XMLHttpRequest.
Can I use PHP do what I'm trying to do?
Here's my code:
The function mySaveFunction() is called by clicking the "Update" button, after the user changes the data which is populated in the form fields, which was retrieved via XMLHttpRequest from an XML external file.
I know that...
|
by: wenijah |
last post by:
Hi everyone!
First thank you for reading this post and yes, you probably already see that kind of topic title somewhere but the problem I've got today might be different than the 100 topics I've seen so far that did not resolve my problem...
Environment and problem: I have a page A with Ajax.js and a <div id="ajx">Content</div> that changes when clicking on a link. Another page, page B, gets loaded into page A and (tries) to load a...
|
by: My Pet Programmer |
last post by:
The way I usually set up and work with the XMLHttpRequest to execute
server side functions and get results is this:
var url = "someurl?params=" + params;
var conn = createRequest(); // gets an XMLHttpRequest object
conn.open("GET", url);
conn.onreadystatechange =
function () {
if (conn.readyState == 4 && conn.status == 200) {
|
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: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
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: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |