473,386 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

inline javascript not working while reading from XMLHttpRequest object

Dear Folks,

I stumbled upon a strange behaviour of the XMLHttpRequest.. Maybe I'm
just not well informed enough about its possibilities, so could someone
please confirm my question?

When I put plain javscript in a file that is read-in through a
XMLHttpRequest-object, it's like it is totally ignored. Eg. I have the
file ajax_include.html with in it's body the following lines
<script type="text/javascript" language="javascript">
alert('some alert');
</script>
when I directly surf to the file, the alert pops up as expected, but
when I use a simple XMLHttpRequest to replace the contents of a div
with the contents of this page, the alert is not popping up, although
when I view the selection's source (Thank you, Firefox!), it is there!

When I place an anchor with an onclick-action (eg. alert('onclick')),
it works when I click it.
So my "conclusion" is that it seems like inline javascript commands are
ignored (functions not recognized etc.). All actions assigned to other
events work nice though.

Can someone confirm this strange behaviour? Or is it just normal with
the use of an XMLHttpRequest opbject?

Many regards already!

Jun 9 '06 #1
1 2156
Hi,

4l*****@gmail.com wrote:
Dear Folks,

I stumbled upon a strange behaviour of the XMLHttpRequest.. Maybe I'm
just not well informed enough about its possibilities, so could someone
please confirm my question?

When I put plain javscript in a file that is read-in through a
XMLHttpRequest-object, it's like it is totally ignored. Eg. I have the
file ajax_include.html with in it's body the following lines
<script type="text/javascript" language="javascript">
alert('some alert');
</script>
when I directly surf to the file, the alert pops up as expected, but
when I use a simple XMLHttpRequest to replace the contents of a div
with the contents of this page, the alert is not popping up, although
when I view the selection's source (Thank you, Firefox!), it is there!

When I place an anchor with an onclick-action (eg. alert('onclick')),
it works when I click it.
So my "conclusion" is that it seems like inline javascript commands are
ignored (functions not recognized etc.). All actions assigned to other
events work nice though.

Can someone confirm this strange behaviour? Or is it just normal with
the use of an XMLHttpRequest opbject?

Many regards already!


Actually, the problem is not with the XmlHttpRequest, but rather with
the way the interpreter works.

When a webpage is loaded, every JavaScript code is interpreted, and
global instructions are executed. When you use DOM functions to add some
JavaScript code to the page, and since the page is already loaded, the
global code won't be executed again (what is the behaviour you expected?
That all global JavaScript code on the page would be executed again? Or
only the snippet you add to the page?

Global code is not a good idea anyway. Wrap your code in a function, and
you events or normal function calls to execute it, that's my advice.

Greetings,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch
Jun 9 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: mikeyjudkins | last post by:
Ive been banging my head on the wall for hours with this one, hopefully someone will know what Im doing wrong here :\ The Goal: I have an xml file that is generated on the fly via JSP which I...
4
by: bobzimuta | last post by:
I'm creating a simple AJAX library. It's an object that will return an array containing the response text or xml. I'm trying to find a way to assign the response as a property of the object, but...
3
by: SM | last post by:
Hello, Im trying to access elements in my XML file using the JavaScript DOM but i'm not sure how. I use AJAX to access the XML and then use the responseXML property to access the XML file data. I...
20
RMWChaos
by: RMWChaos | last post by:
Currently testing in: WinVista / IE7 I have been working on getting xmlhttprequest going for weeks now. I have finally gotten a semi-working script going. Pulling up text or xml files works great...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.