471,596 Members | 849 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,596 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 1333
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

21 posts views Thread by javainfo | last post: by
10 posts views Thread by Steve | last post: by
3 posts views Thread by Ivan P | last post: by
4 posts views Thread by UKuser | last post: by
2 posts views Thread by Jeremy | last post: by
reply views Thread by XIAOLAOHU | last post: by

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.