Web Hosting Talk







View Full Version : Ajax and jQuery interaction problem


computerwiz3491
04-19-2009, 10:08 PM
I am using an this ajax call to get content to put in the center of a page:


function getPage()
{
xmlHttpw=GetXmlHttpObject();
if (xmlHttpw==null)
{
alert ("Your browser does not support AJAX!");
return;
}
var url="testmiddle.htm?id=123";
xmlHttpw.onreadystatechange=stateChanged8;
xmlHttpw.open("GET",url,true);
xmlHttpw.send(null);
}

function stateChanged8()
{
if (xmlHttpw.readyState==4)
{
document.getElementById("center").innerHTML=xmlHttpw.responseText;
}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}

This is how I learned to use AJAX and have always used it this way successfully. Now I am involved in coding a site that uses the JQuery library to do things like expand an area on mouseover and switch tabs on a page. The page I am trying to call in (testmiddle.htm) contains this sort of thing (mouseovers and switching tabs). The page works fine if I go directly to it, but in FF and Safari, when it is called into another page via ajax, it stops working (you can't switch tabs and the mouseovers don't do anything). In IE it works OK.

I tried this:

var html;
var center;
$.ajax({
url: "testmiddle.htm",
success: function(response){
$("#center").html(response);
}
});
which seems to make it work in FF sometimes, but then it won't load at all in IE and still won't switch tabs or do the mouseovers in safari.

HELP!!

Thanks

xphoid
04-19-2009, 10:37 PM
Why not use jQuery's built in ajax methods?

http://docs.jquery.com/Ajax

For your script it would probably look something like this..
$.get('testmiddle.htm', function(data){
$("#center").html(data);});

computerwiz3491
04-19-2009, 10:51 PM
Why not use jQuery's built in ajax methods?

http://docs.jquery.com/Ajax

For your script it would probably look something like this..
$.get('testmiddle.htm', function(data){
$("#center").html(data);});

Thanks but still no go for Safari or IE with any of those functions. Safari still won't do mouseovers etc. and IE won't even display it.

sasha
04-20-2009, 09:34 AM
Are there any JS errors? Could it be that content you add to the page using ajax conflicts with existing content on the page (duplicate ids)? It would be much easier to help you out if you would post link to actual example page.