473,404 Members | 2,137 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,404 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 24 '06 #1
3 1567
Ivan P wrote:
[snip]
<span onclick="loadHTML(file.php','')">Click</span><br>
Is this really the code? Missing a ' before file.php and no dest specified?
[snip]
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?


I'm not sure but perhaps when setting the innerHTML property the browser
doesn't parse it for javascript?

Robin
May 25 '06 #2
The problem is that the javascript executes before the rendering is
done of the page.

Can you put an alert in its place to confirm this?

May 26 '06 #3
> 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?


1. The document.write method can only be called while the page is
loading, if we call it after the page was loaded or with any events,
or with AJAX script, it will replace whole HTML data in IE, and
in Firefox, it will do nothing.
2. If the script tag is created dynamically by changing some
element's innerHTML, it won't be executed.

My way to create script on the fly is using this script
scriptObj =
document.body.appendChild(document.createElement(' script'));
scriptObj.type = 'text/javascript';
scriptObj.src = '<link to js file>';

May 28 '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: 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
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,...
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...
0
agi2029
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.