Ajax is not working in firefox and opera | Newbie | | Join Date: May 2007
Posts: 28
| |
I have the following javascripts which is working in IE, but not working in Firefox and opera. - var xmlhttp=null;
-
function showCustomer(str)
-
{
-
xmlhttp=getxmlhttp();
-
-
if (xmlhttp==null)
-
{
-
alert("Your Browser does not support AJAX");
-
return;
-
}
-
-
var url="search.php";
-
url=url+"?q="+str;
-
url=url+"&sid="+Math.random();
-
xmlhttp.onreadyStateChange=statechanged;
-
xmlhttp.open('get',url,false);
-
xmlhttp.send(null);
-
-
-
}
-
-
function statechanged()
-
{
-
alert("ok");
-
if (xmlhttp.readyState==4)
-
{
-
-
document.getElementById("txt").innerHTML=xmlhttp.responseText;
-
-
}
-
-
}
-
-
function getxmlhttp()
-
{
-
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;
-
}
How to solve this problem.
Thanks in advance
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | re: Ajax is not working in firefox and opera
Welcome to TSDN.
The probable reason why it is not working is that the global variable is "xmlhttp", but when using the XMLHttpRequest object, you have used "xmlHttp" (note the case difference).
| | Newbie | | Join Date: May 2007
Posts: 28
| | | re: Ajax is not working in firefox and opera Quote:
Originally Posted by acoder Welcome to TSDN.
The probable reason why it is not working is that the global variable is "xmlhttp", but when using the XMLHttpRequest object, you have used "xmlHttp" (note the case difference).
Thanks for the response.
I have changed all varables as "xmlhttp". But still above problem exists. ie It is working in IE and not in firefox and opera.
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | re: Ajax is not working in firefox and opera
Perhaps onreadyStateChange should be onreadystatechange.
What error do you get? Check the console for errors or Firebug if you have it.
| | Newbie | | Join Date: May 2007
Posts: 28
| | | re: Ajax is not working in firefox and opera Quote:
Originally Posted by acoder Perhaps onreadyStateChange should be onreadystatechange.
What error do you get? Check the console for errors or Firebug if you have it.
Thanks a lot
My code is working in firefox as well as in opera. I have changed onreadyStateChange to onreadystatechange .Then it is working in Opera, but not in firefox. . After this , I changed xmlhttp.open('GET',url,false) to xmlhttp.open('GET',url,true) .Now it is working IE, Opera and Firefox.
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | re: Ajax is not working in firefox and opera Quote:
Originally Posted by benoypaul Thanks a lot
My code is working in firefox as well as in opera. I have changed onreadyStateChange to onreadystatechange .Then it is working in Opera, but not in firefox. . After this , I changed xmlhttp.open('GET',url,false) to xmlhttp.open('GET',url,true) .Now it is working IE, Opera and Firefox. It's good that you got it working, but how did it work in the other browsers with those mistakes. That last argument makes AJAX asynchronous.
| | Newbie | | Join Date: Feb 2008
Posts: 1
| | | re: Ajax is not working in firefox and opera Quote:
Originally Posted by benoypaul I have the following javascripts which is working in IE, but not working in Firefox and opera.
var xmlhttp=null;
function showCustomer(str)
{
xmlhttp=getxmlhttp();
if (xmlhttp==null)
{
alert("Your Browser does not support AJAX");
return;
}
var url="search.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlhttp.onreadyStateChange=statechanged;
xmlhttp.open('get',url,false);
xmlhttp.send(null);
}
function statechanged()
{
alert("ok");
if (xmlhttp.readyState==4)
{
document.getElementById("txt").innerHTML=xmlhttp.r esponseText;
}
}
function getxmlhttp()
{
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;
}
How to solve this problem.
Thanks in advance *********************************
xmlhttp.open('get',url,false);
Replace with
xmlhttp.open('get',url,true);
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | re: Ajax is not working in firefox and opera
Hi, welcome to TSDN! Thanks for posting. Quote:
Originally Posted by delhiloves10 *********************************
xmlhttp.open('get',url,false);
Replace with
xmlhttp.open('get',url,true); benoypaul managed to solve this, but thanks anyway for pointing out the change required.
| | Newbie | | Join Date: Sep 2008
Posts: 1
| | | re: Ajax is not working in firefox and opera Quote:
Originally Posted by benoypaul ...I changed xmlhttp.open('GET',url,false) to xmlhttp.open('GET',url,true) .Now it is working IE, Opera and Firefox. Thank you for the info! Was having the same issue and this resolved it for me as well.
|  | Similar JavaScript / Ajax / DHTML bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,223 network members.
|