views:

682

answers:

4

I asked,

Can you tell me why my searches are working ok in IE8 but get stuck with safari and chrome?

www.netivot.biz

The ajax code is at www.netivot.biz/js/Ajax.js

It works with some xml and xslt files

then jitter suggested to preplace my code with :

function getAjaxObject() {
  var xmlHttp = null;  
  try {    
    //FF, Opera, Safari, Chrome, IE7+
    xmlHttp = new XMLHttpRequest();  
 } catch(e) {    
     try {      
       //IE6+
          xmlHttp  = new ActiveXObject("Microsoft.XMLHTTP");    
     } catch(e) {
          try {
            //IE5+
            xmlHttp  = new ActiveXObject("Msxml2.XMLHTTP");
          } catch(e) {
            xmlHttp  = null;
          }
     }
 }  
 return xmlHttp;}

but still dont work on safari and chrome any advise?

+2  A: 

Try this one out, it has the benefit of not being browser dependent.

 // Browser-agnostic factory function
 _createXMLHttpRequest: function() {
   if (window.XMLHttpRequest) {
     return new XMLHttpRequest();
   } else if (window.ActiveXObject) {
     return new ActiveXObject('Microsoft.XMLHTTP')
   } else {
     _error("Could not create XMLHttpRequest on this browser");
     return null;
   }
 },

More information:

Ian Robinson
replaced the code and still same .... :(
qaedus
+1  A: 
<script type="text/javascript">
function ajaxFunction()
{
var xmlhttp;
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else if (window.ActiveXObject)
  {
  // code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
else
  {
  alert("Your browser does not support XMLHTTP!");
  }
}
</script>

this piece of code is available in W3Schools you can learn basics here like i did. hope this helps.

tony_le_montana
A: 

Strange. All the suggestions shall work. Anyway, here is what I use and it works at least for my websites.

return window.ActiveXObject ?
    new ActiveXObject("Microsoft.XMLHTTP"): new XMLHttpRequest()
Mo
+3  A: 

Would you try using jQuery or some other library's ajax functions?

dlamblin