Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Ajax code showing problem in IE6 / Firefox

Posted on 2009-02-21
13
Medium Priority
?
486 Views
Last Modified: 2012-05-06
I m using following code to get  xmlHttpRequest object , bt its failing

var xmlHttp;
try
  {  // Firefox, Opera 8.0+, Safari  xmlHttp=new XMLHttpRequest();  }
catch (e)
  {  // Internet Explorer  try
    {    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    }
  catch (e)
    {    try
      {      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      }
    catch (e)
      {      alert("Your browser does not support AJAX!");      return false;      }    }  }  }



and also i tried with following code

var xmlhttp = false;

try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
      try {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
            xmlhttp = false;
      }
}
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
            xmlhttp = new XMLHttpRequest();
}


but everytime I m getting same alert "Your browser does not support AJAX!"

any solution  its urgent
0
Comment
Question by:emsysindia
  • 6
  • 3
  • 3
  • +1
13 Comments
 
LVL 5

Expert Comment

by:striker46
ID: 23699835
This one works, see it here in action: http://aleixcortadellas.com/demos/ajaxnavigation/





function AJAX()
{
 
var xmlHttp;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
return xmlHttp;
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
return xmlHttp;
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
return xmlHttp;
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
}

Open in new window

0
 
LVL 5

Expert Comment

by:striker46
ID: 23699847
If you want to call the code directly and not in the function, remove the function { } so it is like below

var xmlHttp;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
return xmlHttp;
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
return xmlHttp;
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
return xmlHttp;
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}

Open in new window

0
 
LVL 5

Expert Comment

by:striker46
ID: 23699855
Ooops... to call it directly and from outside the function you need to remove the "return" too
(I forgot,...)

Btw this is an implementation of the code suggested at
http://www.w3schools.com/ajax/ajax_browsers.asp



var xmlHttp;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}

Open in new window

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 29

Expert Comment

by:Badotz
ID: 23699858
Or this:


function getXmlHttp() {
	var x = 
	[
		function() { return new XMLHttpRequest(); }, 
		function() { return new ActiveXObject("Msxml2.XMLHTTP"); },
		function() { return new ActiveXObject("Microsoft.XMLHTTP"); }
	];
	for (var i = 0; i < x.length; i++)
	{
		try { var f = x[i]; var r = f(); if (r !== null) { return r; } }
		catch(e) { continue; }
	}
	return null;
}

Open in new window

0
 

Author Comment

by:emsysindia
ID: 23699871
Used  above code but same problem / alert(Your browser does not support AJAX);
I m using IE6 and  Mozila 5.0  
0
 

Author Comment

by:emsysindia
ID: 23699896
I m using the below code

function practice(str)
{
     
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }
 
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET","http://localhost:8080/deleteChk1?user="+str,true);
xmlHttp.send(null);
}
 
function stateChanged()
{
      var locationName;
if (xmlHttp.readyState==4)
{
document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
 
locationName = xmlHttp.responseText;
alert(xmlHttp.responseText);
}
}
 
function GetXmlHttpObject()
{
var xmlHttp;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
return xmlHttp;
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
return xmlHttp;
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
return xmlHttp;
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
}
 
 
 
 
<body>
 
<select name="cities1" onchange="practice(this.value);" multiple="multiple"  >
</select>          
 
</body>
0
 
LVL 5

Expert Comment

by:striker46
ID: 23699901
This is strange. If it doesn't work in both browsers I can't think of anything but perhaps something in the rest of your code could be causing interference? Have you tried from another computer so to make sure it is not related with your browsers?
0
 
LVL 5

Expert Comment

by:striker46
ID: 23699918
Try removing the following and see if it fixes it

if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }

Open in new window

0
 
LVL 29

Expert Comment

by:Badotz
ID: 23699923
My code works all of the time. Are you sure you have MSXML installed?
0
 

Accepted Solution

by:
emsysindia earned 0 total points
ID: 23699955
I got , this error was coz of only  calling the servlet class
i was using

xmlHttp.open("GET","http://localhost:8080/deleteChk1?user="+str,true);
I removed  "http://localhost:8080/" and simply calling  deleteChk1 java class and its working
 
 
 
 
0
 
LVL 5

Expert Comment

by:striker46
ID: 23699965
Good to know you got it to work. Was a bit strange the XMLHTTPReq codes didn't work to you in two different browsers...
0
 
LVL 29

Expert Comment

by:Badotz
ID: 23699968
Please PLEASE do not call JavaScript "Java" - the two languages have NOTHING to do with one another. And yes, details MATTER.
0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 23703341
>>xmlHttp.open("GET","http://localhost:8080/deleteChk1?user="+str,true);
this call will be AFTER the creation of XmlHttpRequest..

If you were getting the alert ( "does not support ajax").. I do not think it will be fixed by changing your url..
there has to be something else that also changed.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There is basically two types of AJAX request in mootools. Request  and Request.HTML Request: Request is the basic XHR request class in MooTools. While not extremely useful on its own, it provides the basic functionality for both Request.HTM…
Today I am discussing AJAX problems in IE7 and I bet this will helps many guys out here who have problems with AJAX work. Lets start with the discovery of problem and then we will talk about its different solutions. My last two projects included …
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Loops Section Overview
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question