...

View Full Version : Newbie AJAX



lesmith
04-06-2006, 11:40 PM
Hello Peeps.

Sorry if this is basic stuff but I am waiting for my Book to arive and tring to do a little bit before it arrives.

I have a simple script to collect some php data (Just some Text) and display in div on mouseover.

All works fine apart from if I update the data (In other words add more text). The update happens correctly in Firefox but Not in IE.

Here is the simple script.

Hopefully some one can give me some pinters.



<script type="text/javascript">
var XMLHttpRequestObject = false;

if (window.XMLHttpRequest) {
XMLHttpRequestObject = new XMLHttpRequest();
} else if (window.ActiveXObject) {
XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
}

function getData(dataSource, divID)
{
if(XMLHttpRequestObject) {
var obj = document.getElementById(divID);
XMLHttpRequestObject.open("GET", dataSource);

XMLHttpRequestObject.onreadystatechange = function()
{
if (XMLHttpRequestObject.readyState == 4 &&
XMLHttpRequestObject.status == 200) {
obj.innerHTML = XMLHttpRequestObject.responseText;
}
}

XMLHttpRequestObject.send(null);
}
}
</script>

And the HTML.

<a href="#" onmouseover="getData('/includes/data.php?event=showuser', 'targetDiv')">Show Users</a> | <a href="#" onmouseover="getData('/includes/data.php?event=showblog', 'targetDiv')">Show Latest Blog</a>

<div id="targetDiv"></div>


I guess this has something to do with the DOM and ie.

Hope you can shed some light.

Regards & Thanks

A1ien51
04-07-2006, 03:43 PM
Answered here:

http://www.ajaxforums.net/forums_topic.php?id=312

Eric

lesmith
04-07-2006, 08:48 PM
Hello Again Eric

That didnt work.

Regards

Lee

A1ien51
04-10-2006, 09:49 PM
You ever look at my answer?

Basscyst
04-10-2006, 11:24 PM
I'm not sure if this will solve your problem or not, and I didn't really read through Eric's replies, but you may try just appending the current date / time to your url or post string. I had the problem you describe before and it seems to have rectified it.

Example:



function getReqObj(url,func)
{
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
if(new ActiveXObject("Microsoft.XMLHTTP"))
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
else
{
xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
}
}
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4)
{
if(xmlhttp.status==200)
{
if(document.getElementById('nextPage'))
{
document.getElementById('nextPage').style.display='inline';
}
var last_mod=xmlhttp.getResponseHeader("Last-Modified");
var req=xmlhttp.responseXML;
var req_str=xmlhttp.responseText;
eval(func);
}
else
{
noData(xmlhttp.status);
}
}
}
var now=new Date();

if(url.indexOf("?")==-1)
{
var cut=url.substring(0,url.length);
var s=cut+"?c_date="+now;
}
else
{
var cut=url.split('?');
var s=cut[0]+"?c_date="+now+"&"+cut[1];
}
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}


Basscyst

A1ien51
04-11-2006, 03:21 AM
Basscyst,

You need to have try catch around the ActiveX portion. If ActiveX is disabled you get an error message.

Eric

mlanka
04-11-2006, 11:27 AM
30 AJAX Tutorials....
http://www.maxkiesler.com/index.php/weblog/comments/round_up_of_30_ajax_tutorials/

Basscyst
04-11-2006, 05:48 PM
Basscyst,

You need to have try catch around the ActiveX portion. If ActiveX is disabled you get an error message.

Eric

Okay. I'll add that in, thanks.

Basscyst



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum