473,394 Members | 1,766 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,394 software developers and data experts.

ajax & php & javascript

Hello!

I have a index.php that on one click calls via AJAX a file.php.

index.php looks like this:

<html >
<head>

<script language="javascript" type="text/javascript" >
var http; // We create the HTTP Object
var dest;
var prenosi;
function getHTTPObject() {
var xmlhttp;
/*@cc_on
@if (@_jscript_version >= 5)
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
@else
xmlhttp = false;
@end @*/
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
xmlhttp = false;
}
}
return xmlhttp;
}

function processStateChange(){
if (http.readyState == 4){
contentDiv = document.getElementById(dest);
if ((http.status == 200)||(http.status==0)){
response = http.responseText;
contentDiv.innerHTML = response;
} else {
contentDiv.innerHTML = "Error: Status "+http.status;
}
}
}

function loadHTML(URL, destination){
dest = destination;
var url;
http = getHTTPObject();
if(http){
http.onreadystatechange = processStateChange;
http.open("GET", URL, true);
http.send(null);
}
}

</head>
<body>

<span onclick="loadHTML(file.php','')">Click</span><br>
</html>

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - -

file.php looks like this:

<span id="countdowncontainer">
write something down
<script type="text/javascript">
document.write("1")
</script>
</span>

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - -

The problem is that "write something down" displays on the Internet
Explorer, but number 1 doesn't. If we call just file.php - it works then -
it displays both. Why is javascript not executing from ajax called
procedure?

Ivan Petrovic

May 25 '06 #1
3 1396
Ivan P said the following on 5/25/2006 5:55 AM:
Hello!
<snip>
function processStateChange(){
<snip>
contentDiv.innerHTML = response;
<snip>
file.php looks like this:

<span id="countdowncontainer">
write something down
<script type="text/javascript">
document.write("1")
</script>
</span>
<snip>
The problem is that "write something down" displays on the Internet
Explorer, but number 1 doesn't.
It won't in most other browsers as well.
If we call just file.php - it works then - it displays both.
Yes.
Why is javascript not executing from ajax called procedure?


It has nothing to do with it being an "ajax called procedure". It has to
do with inserting the script via innerHTML and the script blocks don't
get processed when doing that.

If you want to execute script blocks, then you will have to use a
different method of inserting it in the page to get the browser - any
browser - to execute the script.

The only browser I recall that executed script's inserted via innerHTML
was NS6.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
May 25 '06 #2
Thanks!

What are other methods than innerHTML that support processing JavaScripts on
callback? ... so I can search a web for examples...

Ivan
"Randy Webb" <Hi************@aol.com> wrote in message
news:4N******************************@comcast.com. ..
Ivan P said the following on 5/25/2006 5:55 AM:
Hello!


<snip>
function processStateChange(){


<snip>
contentDiv.innerHTML = response;


<snip>
file.php looks like this:

<span id="countdowncontainer">
write something down
<script type="text/javascript">
document.write("1")
</script>
</span>


<snip>
The problem is that "write something down" displays on the Internet
Explorer, but number 1 doesn't.


It won't in most other browsers as well.
If we call just file.php - it works then - it displays both.


Yes.
Why is javascript not executing from ajax called procedure?


It has nothing to do with it being an "ajax called procedure". It has to
do with inserting the script via innerHTML and the script blocks don't get
processed when doing that.

If you want to execute script blocks, then you will have to use a
different method of inserting it in the page to get the browser - any
browser - to execute the script.

The only browser I recall that executed script's inserted via innerHTML
was NS6.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices -
http://www.JavascriptToolbox.com/bestpractices/

May 25 '06 #3
Ivan P said the following on 5/25/2006 9:48 AM:
Thanks!

What are other methods than innerHTML that support processing JavaScripts on
callback? ... so I can search a web for examples...


createElement, appendChild.

Dynamically loading a JS file.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
May 25 '06 #4

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

Similar topics

4
by: k.mitz | last post by:
Hi, I have a PHP application that allows users to generate a .pdf report of their database content. Normally, I've had to refresh a page to call the script to generate the report, so there's a...
21
by: javainfo | last post by:
How can i refresh IFRAME and load data through AJAX?
10
by: Steve | last post by:
I need to build a very dynamic client and would be interested in knowing the pros and cons of using JSF and Ajax to accomplish this. Thanks. Steve
3
by: Ivan P | last post by:
Hello! I have a index.php that on one click calls via AJAX a file.php. index.php looks like this: <html > <head> <script language="javascript" type="text/javascript" >
4
by: UKuser | last post by:
Hi, I'm working on the following code, which works fine in Firefox, but not in IE. The problem is its not posting the variable to my page and I'm thinking its something wrong with the...
2
by: Nathan Sokalski | last post by:
I am moving my website from my machine to my webhost, and need some help with what extra files I need to include due to the fact that I used AJAX in my site. Everything on the site is obviously...
0
by: Tarik Monem | last post by:
I have been working on an all AJAX/DOM web site which is set to go live today and I thought I'd share my discoveries with all of you whom have helped me when I have encountered different issues along...
2
by: Jeremy | last post by:
I've got a very large listbox that gets populated using ajax. The listbox and a button are in a panel inside an update panel. The button click of the button sets the panel visible property to...
1
by: fidgen | last post by:
Hiya, I'm trying to get a AJAX driven update to my list of news articles, so when users click the title of the news article, it pops up the article content in a thickbox overlay. Retrieving...
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: 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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
jinu1996
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...
0
tracyyun
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...

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.