473,698 Members | 2,166 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Ajax is not working in firefox and opera

28 New Member
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 9434
acoder
16,027 Recognized Expert Moderator MVP
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
benoypaul
28 New Member
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 Recognized Expert Moderator MVP
Perhaps onreadyStateCha nge should be onreadystatecha nge.

What error do you get? Check the console for errors or Firebug if you have it.
May 3 '07 #4
benoypaul
28 New Member
Perhaps onreadyStateCha nge should be onreadystatecha nge.

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 onreadyStateCha nge to onreadystatecha nge .Then it is working in Opera, but not in firefox. . After this , I changed xmlhttp.open('G ET',url,false) to xmlhttp.open('G ET',url,true) .Now it is working IE, Opera and Firefox.
May 4 '07 #5
acoder
16,027 Recognized Expert Moderator MVP
Thanks a lot

My code is working in firefox as well as in opera. I have changed onreadyStateCha nge to onreadystatecha nge .Then it is working in Opera, but not in firefox. . After this , I changed xmlhttp.open('G ET',url,false) to xmlhttp.open('G ET',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
delhiloves10
1 New Member
I have the following javascripts which is working in IE, but not working in Firefox and opera.

var xmlhttp=null;
function showCustomer(st r)
{
xmlhttp=getxmlh ttp();

if (xmlhttp==null)
{
alert("Your Browser does not support AJAX");
return;
}

var url="search.php ";
url=url+"?q="+s tr;
url=url+"&sid=" +Math.random();
xmlhttp.onready StateChange=sta techanged;
xmlhttp.open('g et',url,false);
xmlhttp.send(nu ll);


}

function statechanged()
{
alert("ok");
if (xmlhttp.readyS tate==4)
{

document.getEle mentById("txt") .innerHTML=xmlh ttp.responseTex t;

}

}

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.XMLHT TP");
}
}
return xmlHttp;
}


How to solve this problem.

Thanks in advance
*************** *************** ***

xmlhttp.open('g et',url,false);

Replace with

xmlhttp.open('g et',url,true);
Feb 8 '08 #7
acoder
16,027 Recognized Expert Moderator MVP
Hi, welcome to TSDN! Thanks for posting.
*************** *************** ***

xmlhttp.open('g et',url,false);

Replace with

xmlhttp.open('g et',url,true);
benoypaul managed to solve this, but thanks anyway for pointing out the change required.
Feb 8 '08 #8
mindvamp
1 New Member
...I changed xmlhttp.open('G ET',url,false) to xmlhttp.open('G ET',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
11873
by: Arjen | last post by:
Hi, I want to reload 2 divs at one click. Ive tried: <a href = "javascript:void(0);" onclick="show('ajaxrequest.php?action=removefield','div1');show('ajaxrequest.php?action=reloaddiv2','div2')">verwijderen</a> While both seperate actions work they dont when I put them together. Anyone know how to fix this ? My ajax.js with funcition show
5
6414
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 login page, you can test it using the details User: marco Pass: polo This seems to work PERFECTLY in opera, and it works in firefox but ONLY if I have firebug enabled. I don't care about IE for now, I'll sort that out later.
8
3309
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 trigger. If I use click events then the AJAX bit breaks. Here's the code (mostly): Adding event listener to all links (firefox tells me errors but it works?!). When I switch from mouseover to click, the whole thing breaks down. function...
2
3164
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 i change something in php file using in ajax function.it not refreshed,means its shows the previous result it not get updated.i can't understand whats the prob.this is the code i m using: <? include("config.inc.php"); //error_reporting(0); ...
1
2076
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' the page with the results that have been retrieved thus far. This 2nd call loops until the first call (the search) is complete. Everything works fine in Firefox, but in IE, the 2nd call doesn't work until the very end when the 1st call is complete....
7
1148
by: theS70RM | last post by:
hi guys, My code suddenly stopped working here it is: function Ajax(page,data){ page = "includes/" + page;
29
3308
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 use it in sync mode. Any ideas what can I do? Thanks, Zalek.
1
4603
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 Database but I'm stuck in the EDIT. I'm getting 2 problems over here. Below is the description: 1)The FIRST page will list all the records from the table which Admin can EDIT with CHECKBOX for each record to select. He can select one or more than one...
7
4037
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. Before there are six characters entered in the CAPTCHA code field, the 'Send' button is supposed to be disabled. When there are at least six characters in the CAPTCHA code field, the script attempts to verify the CAPTCHA w/AJAX. If it verifies, it...
0
9160
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9029
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7729
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6521
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3050
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2331
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2002
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.