473,763 Members | 6,772 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="javas cript" type="text/javascript" >
var http; // We create the HTTP Object
var dest;
var prenosi;
function getHTTPObject() {
var xmlhttp;
/*@cc_on
@if (@_jscript_vers ion >= 5)
try {
xmlhttp = new ActiveXObject(" Msxml2.XMLHTTP" );
} catch (e) {
try {
xmlhttp = new ActiveXObject(" Microsoft.XMLHT TP");
} catch (E) {
xmlhttp = false;
}
}
@else
xmlhttp = false;
@end @*/
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
try {
xmlhttp = new XMLHttpRequest( );
} catch (e) {
xmlhttp = false;
}
}
return xmlhttp;
}

function processStateCha nge(){
if (http.readyStat e == 4){
contentDiv = document.getEle mentById(dest);
if ((http.status == 200)||(http.sta tus==0)){
response = http.responseTe xt;
contentDiv.inne rHTML = response;
} else {
contentDiv.inne rHTML = "Error: Status "+http.stat us;
}
}
}

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

</head>
<body>

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

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

file.php looks like this:

<span id="countdownco ntainer">
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 1405
Ivan P said the following on 5/25/2006 5:55 AM:
Hello!
<snip>
function processStateCha nge(){
<snip>
contentDiv.inne rHTML = response;
<snip>
file.php looks like this:

<span id="countdownco ntainer">
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.javas cript 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 processStateCha nge(){


<snip>
contentDiv.inne rHTML = response;


<snip>
file.php looks like this:

<span id="countdownco ntainer">
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.javas cript 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.javas cript 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
9555
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 second or so when the browser goes blank. I was wondering if it was possible to use AJAX to call the script to generate the report, then begin the download without refreshing the page (or in the case of I.E., leaving me with a blank window that...
21
6158
by: javainfo | last post by:
How can i refresh IFRAME and load data through AJAX?
10
6315
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
1624
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
2545
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 getElementByID but the code is as per an example on a tutorial website (http://www.tizag.com/ ajaxTutorial/ajax-javascript.php). The Select element is as follows: <select style="width:240px;font-size:8pt" id='servicet'
2
4280
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 functioning as desired when I test it on my machine using Visual Studio 2005. From what I have determined, the files I am forgetting are the JavaScript files from the Microsoft AJAX Library (See "To install Microsoft AJAX Library" at the bottom of...
0
7191
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 the way. First, deep linking is not something that a completely AJAX web site should be able to do by it's very nature of everything being on one page basically. So how can a person deep link to something that is on one page? This question...
2
2036
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 false. Everything works nice and snappy except for when I click the button. The panel takes about 20 or so seconds to dissapear. I think the ajax call has been made and the browser is executing some javascript synchronously because the browser is...
1
4438
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 content from the database via AJAX is no problem, that works and thickbox works too, I'm just having problems getting them both running together! It seems like it's too much information to cram into one poor little "a href=".... the "onclick"...
0
9563
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10144
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9822
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8821
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7366
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3522
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2793
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.