473,387 Members | 1,890 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,387 software developers and data experts.

Ajax is not working in firefox and opera

I have the following javascripts which is working in IE, but not working in Firefox and opera.

Expand|Select|Wrap|Line Numbers
  1. var xmlhttp=null;
  2. function showCustomer(str)
  3. {
  4.   xmlhttp=getxmlhttp();
  5.  
  6. if (xmlhttp==null)
  7. {
  8.   alert("Your Browser does not support AJAX");
  9.   return;
  10.  }
  11.  
  12.  var url="search.php";
  13.  url=url+"?q="+str;
  14.   url=url+"&sid="+Math.random();
  15.    xmlhttp.onreadyStateChange=statechanged;
  16.    xmlhttp.open('get',url,false);
  17.       xmlhttp.send(null);
  18.  
  19.  
  20.   }  
  21.  
  22. function statechanged()
  23. {
  24.  alert("ok"); 
  25.  if (xmlhttp.readyState==4)
  26.  {
  27.  
  28.          document.getElementById("txt").innerHTML=xmlhttp.responseText;
  29.  
  30. }      
  31.  
  32.  }
  33.  
  34.  function getxmlhttp()
  35.  {
  36.    xmlhttp=null;
  37.    try
  38.   {
  39.   // Firefox, Opera 8.0+, Safari
  40.   xmlHttp=new XMLHttpRequest();
  41.   }
  42. catch (e)
  43.   {
  44.   // Internet Explorer
  45.   try
  46.     {
  47.     xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  48.     }
  49.   catch (e)
  50.     {
  51.     xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  52.     }
  53.   }
  54. return xmlHttp;
  55. }

How to solve this problem.

Thanks in advance
May 3 '07 #1
8 9405
acoder
16,027 Expert Mod 8TB
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).
May 3 '07 #2
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.
May 3 '07 #3
acoder
16,027 Expert Mod 8TB
Perhaps onreadyStateChange should be onreadystatechange.

What error do you get? Check the console for errors or Firebug if you have it.
May 3 '07 #4
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.
May 4 '07 #5
acoder
16,027 Expert Mod 8TB
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.
May 4 '07 #6
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);
Feb 8 '08 #7
acoder
16,027 Expert Mod 8TB
Hi, welcome to TSDN! Thanks for posting.
*********************************

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.
Feb 8 '08 #8
...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.
Sep 30 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

17
by: Arjen | last post by:
Hi, I want to reload 2 divs at one click. Ive tried: <a href = "javascript:void(0);"...
5
by: Heofz | last post by:
Hey all, I've been banging my head against a brick wall on this one for the last 12 hours, and the time has come for me to give up and consult the gurus on this one. The below URL contains a...
8
by: henryrhenryr | last post by:
I'm trying to log all links clicked. I'm just working this out so there may be some astoundingly bad methods. Please point out! It all works nicely though if I use mouseover events as the...
2
by: shivendravikramsingh | last post by:
hi friends, i m using a ajax function for retrieving some values from a database table,and display the values in required field,my prob is that the ajax function i m using is working f9 once,but if...
1
by: wpt394 | last post by:
I am running a code that works just fine in Firefox, but seems to have trouble in IE. The basic idea is that a travel search process is initiated with one ajax call, and a 2nd ajax call 'updates'...
7
by: theS70RM | last post by:
hi guys, My code suddenly stopped working here it is: function Ajax(page,data){ page = "includes/" + page;
29
by: zalek | last post by:
I am writing application with Ajax in sync mode - xmlHttp.open("GET", url, false). I noticed that in FireFox handler doesn't starts. It starts when I use xmlHttp.open("GET", url,true). I need to...
1
by: javediq143 | last post by:
Hi All, This is my first post in this forum. I'm developing a CMS for my latest website. This CMS is also in PhP & MySQL. I'm done with the ADD section where the Admin can INSERT new records in...
7
by: mike57 | last post by:
The minimal AJAX script below works in Firefox, but not in IE, Opera, or Chrome. I could use some suggestions or referrals to resources that will help me get the script working in other browsers. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...

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.