473,325 Members | 2,774 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,325 software developers and data experts.

Ajax requested page doesn't run javascript

I have create a AJAX webpage where if you press a link content is
loaded into a div. NOw when this content is loaded no javascript is
processed (i.e <Script>alert(..);</script>), but if the javascript is
in <a onclick="..."> it will work.
What i would like to know is:
- Is this normal
- What do i need to change so that javascript does get processed?

Thanks in advance,
Stephan Maat

Apr 13 '06 #1
2 2123
Hi Stephan,

sg****@gmail.com wrote:
I have create a AJAX webpage where if you press a link content is
loaded into a div. NOw when this content is loaded no javascript is
processed (i.e <Script>alert(..);</script>), but if the javascript is
in <a onclick="..."> it will work.
What i would like to know is:
- Is this normal
- What do i need to change so that javascript does get processed?


Yes it seems to be normal that the javascript in script tags isn't
processed. The javascript in the onclick gets processed when the click
occurs, or so it seems.

Yesterday I went through this very same thing and asked about it here.
The thread was called "run JavaScript that is part of AJAX response".
Lasse gave me some great advice about how to deal with this in my
situation.

http://groups.google.com/group/comp....9890b18d005e9e

It is interesting to note that the Prototype.js Ajax.Updater() function
seems to automatically run the javascript when it inserts the AJAX
response. This is why I've temporarily reverted to using the
Prototype.js library for AJAX until I can try writing some higher level
functions for the Yahoo! UI connection library.

Peter

Apr 13 '06 #2
sg****@gmail.com wrote:
I have create a AJAX webpage where if you press a link content is
loaded into a div. NOw when this content is loaded no javascript is
processed (i.e <Script>alert(..);</script>), but if the javascript is
in <a onclick="..."> it will work.
What i would like to know is:
- Is this normal
Yes, and proper.

When you load a page, the browser parses (and executes) the javascript
in the page. When you place content into a div using an ajax call, the
browser doesn't parse/execute the javascript.

BUT

When you call a function with a onclick, the browser attempts to execute
that function.

I would be cautious about relying on a javascript function included in
the returned data to function properly all the time - better, IMO, to
append it to the page <head>
- What do i need to change so that javascript does get processed?


You want it to be processed when the div content loads?

Then strip out the javascript and execute it in one of two ways:

1) use eval()
2) Use the DOM to add it to the page <head>, then call the function.
Apr 13 '06 #3

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

Similar topics

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...
17
by: petermichaux | last post by:
Hi, Is it possible for an AJAX request to be left open for multiple responses? This could avoid repetitive polling of the server. Thanks, Peter
4
by: VK | last post by:
Google Trends is an all new service (started May 10) and I have not responsability for proper query or data accuracy. Overall seems pretty close to what could be observed by the post history in...
12
by: whreed | last post by:
I am using AJAX XMLhttprequest to request another page on form submit and I am loading that page into a span tag. My issue is that I have more js in the called page that loads a calendar on click...
31
by: Tony | last post by:
I just noticed that prototype.js is one of the files in the Ajax.NET distribution - I'm pretty concerned about this. Does anyone know if this is the same "prototype.js" that is not well-liked...
4
by: evgenyg | last post by:
Hello ! We have the following situation - when Ajax request is sent what's being returned by the server is usually an XML (which is used for DOM updates) but sometimes it's HTML which is a whole...
10
by: J | last post by:
Hi, Ajax question: Can I retrieve an HTML page and use the DOM to grab stuff from the requested page in a similar fashion to an XML page requested in the same manner? Details: I'm requesting...
1
by: geevaa | last post by:
http://www.phpbuilder.com/columns/kassemi20050606.php3 XMLHttpRequest and AJAX for PHP programmers James Kassemi Introduction: Although the concept isn't entirely new, XMLHttpRequest...
1
by: urbn | last post by:
Hi everyone. I am finally starting to focus more time on learning AJAX for the last few days, and I ran into a problem I couldn't find a solution too, or find much info on how to do this. What...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.