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

AJAX, JSON and Microsoft.XMLHTTP

Ike
Ive copied an online example for writing out a php file, programmatically,
then would like to re-display that data in a browswer window that
automatically refreshes as the data file (getdata.php, which is the file I
am programmatically rewriting to elsewhere) gets changed.

I am trying to use AJAX and JSON to do this. I have copied an example of
using HttpRequest Object as the backbone of this from
http://www.w3schools.com/dom/dom_http.asp. Further, I am enclosing both of
my files here, in full as opposed to mere snippets. This code does what I
wish it to do except:
1. It does not update when getdata.php is rewritten. On non MSIE broswers,
it shows when first invoked, but not subsequently.
2. It fails altogether under MSIE (6.026 SP1 || SP2) -- I never get
xmlhttp.readyState==4 under MSIE.

Hoping someone can point me in the right direction here -- I think I almost
have this thing finished. -Ike

//
index.html//////////////////////////////////////////////////////////////////
////////////////////
<html>
<head>
<title>uplog</title>
<script type="text/javascript">
var xmlhttp;
function loadXMLDoc(url)
{
if (document.all){
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
}else{
xmlhttp=new XMLHttpRequest()
}
// code for Mozilla, etc.
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest()
xmlhttp.onreadystatechange=xmlhttpChange
xmlhttp.open("GET",url,true)
xmlhttp.send(null)
}
// code for IE
else if (window.ActiveXObject)
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
if (xmlhttp)
{
xmlhttp.onreadystatechange=xmlhttpChange
xmlhttp.open("GET",url,true)
xmlhttp.send()
}
}
}

function xmlhttpChange()
{
// if xmlhttp shows "loaded"
if (xmlhttp.readyState==4)
{
// if "OK"
if (xmlhttp.status==200)
{
var rows = eval(xmlhttp.responseText);
var html = "<table>";

for(r in rows){
html+="<tr>";
html+="<td>"+rows[r].username+"</td>";
html+="</tr>";
}
html+="</table>";
document.getElementById("data").innerHTML = html;
}
else
{
//alert("Problem retrieving XML data")
}
}
}
</script>
</head>
<body>
<div id="data">
</div>
<script>
loadXMLDoc('http://127.0.0.1/roomx1/getdata.php');
</script>
</body>
</html>

// getdata.php
////////////////////////////////////////////////////////////////////////////
////////////////////
<?php
ini_set('include_path',ini_get('include_path').";C :\Program Files\Apache
Group\Apache2\htdocs"."\pear");
require('JSON.php');
$records=array();
$records[]=array('order'=>1, 'username'=>'tommy');
$records[]=array('order'=>2, 'username'=>'ralph');
$records[]=array('order'=>3, 'username'=>'eod');
$records[]=array('order'=>4, 'username'=>'howard');
$json=new Services_JSON();
echo($json->encode($records));
?>
Mar 27 '06 #1
1 4885
> Ive copied an online example for writing out a php file, programmatically,
then would like to re-display that data in a browswer window that
automatically refreshes as the data file (getdata.php, which is the file I
am programmatically rewriting to elsewhere) gets changed.
then you need to poll for new data, using loadXMLDoc()
I am trying to use AJAX and JSON to do this. I have copied an example of
using HttpRequest Object as the backbone of this from
http://www.w3schools.com/dom/dom_http.asp. Further, I am enclosing both of
my files here, in full as opposed to mere snippets. This code does what I
wish it to do except:
1. It does not update when getdata.php is rewritten. On non MSIE broswers,
it shows when first invoked, but not subsequently.
You need to put some header()'s into getdata.php, like no-cache ...
or/and use xmlhttp.setRequestHeader('If-Modified-Since' ...)
2. It fails altogether under MSIE (6.026 SP1 || SP2) -- I never get
xmlhttp.readyState==4 under MSIE.


Try to include Cross-Browser script: "xmlhttprequest.js" from:
http://www.scss.com.au/family/andrew...mlhttprequest/

and it might work in MSIE 6, try pointing on the bold text (tooltip)
here: http://bomlo.com/ does it work in IE ? (and Opera, Firefox, .. :)

Then loadXMLDoc() could be changed to:

var xmlhttp;

function loadJSONDoc(url)
{
xmlhttp= new XMLHttpRequest();
if( xmlhttp )
{
xmlhttp.onReadyStateChange= xmlhttpChange;
xmlhttp.open('GET',url);
xmlhttp.send();
}
}

arnulf @ http://rlb.no/
Mar 28 '06 #2

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

Similar topics

13
by: iannorton | last post by:
Hi there, I Recently started experimenting with AJAX and succesfully created an autocomplete box using a script that returned html from a serverside javascript page. I'm now at the point...
17
by: Arjen | last post by:
Hi, I want to reload 2 divs at one click. Ive tried: <a href = "javascript:void(0);"...
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...
6
by: =?Utf-8?B?U2hhd24gU2VzbmE=?= | last post by:
Greetings! I was researching AJAX to provide a solution to displaying status messages while a long process executed. I found several examples online and was able to use their code to get a quick...
4
balajibirlasoft
by: balajibirlasoft | last post by:
Am using a default converter object in ajax to convert the tables collection to a JSON string. First Input for toJSON Method is strTempData(String Builder) Second Input is the object for which...
8
by: Rory Becker | last post by:
Hi All I have a need for an asp.net page to make a call to a server which it did not originate from when a button is clicked. A simple call to pass 2-3 params and return a result. I am happy...
6
by: KDawg44 | last post by:
Hi, My responseXML is always null on my AJAX call. When I browse directly to the PHP script I am calling, the XML file shows up just fine. I have read that if a returned XML file is not...
1
by: par7133 | last post by:
Hi, Yea, XMLHttpRequest give out a crossbrowser problem managing the status change of the connection. Here the solution: var xmlhttp; xmlhttp=null;
3
by: George | last post by:
I am doing an AJAX call using JQuery on my page to which returns JSON objects and everything works fine. Now I decided to use ashx handler instead of and simply write JSON out. Then my problems...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...

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.