Jump to content

[SOLVED] Internet Explorer doesn't seem to support AJAX at all


leafface

Recommended Posts

Hello,

 

I get the "Object doesn't support this property or method" in any case in IE. As far as i know, it's because the shitty Microsoft XmlHttp object doesn't support many common JS methods for AJAX, such as getElementById. But even if i remove everything, till there is no JS code left (except the XmlHttp object creation, the error reporting function and the empty function), i keep getting this message.

 

Can anyone help please?

Link to comment
Share on other sites

ie does support getElementById and it is not dependant on ajax.  ajax is actually inplemented in ie as an ActiveXObject.  Cross browser code:

function GetXmlHttpObject()
{
    var AjaxObj = false; 
    try{
           /* Opera 8.0+, Firefox, Safari */
           AjaxObj = new XMLHttpRequest();
    } catch (e){
               /* Internet Explorer Browsers */
          try{
               AjaxObj = new ActiveXObject("Msxml2.XMLHTTP");
               } catch (e) {
                    try{
                          AjaxObj = new ActiveXObject("Microsoft.XMLHTTP");
                         } catch (e){
                               /* Something went wrong */
                               ; /* uses default of false for AjaxObj */
                         }
                }
     }
        return AjaxObj;
}

Just what is the statement that causes the error?  Determine that first.

Link to comment
Share on other sites

I have no idea what statement causes the error, IE even screws it up, when there is almost no code at all, only the object creation, the function of the action and an error reporting. The minimalized code looks like this:

 

XMLHttp Object:

{literal}
<script type="text/javascript">

//*
/* Error reporting
*/
onerror=reporterror
function reporterror(msg,url,l) {alert(l+". --> "+msg)}

//*
/* XMLHttp Object
*/
var http=createRequestObject()

function createRequestObject() {
    var AjaxObj = false;
    try{
           /* Opera 8.0+, Firefox, Safari */
           AjaxObj = new XMLHttpRequest();
    } catch (e){
               /* Internet Explorer Browsers */
          try{
               AjaxObj = new ActiveXObject("Msxml2.XMLHTTP");
               } catch (e) {
                    try{
                          AjaxObj = new ActiveXObject("Microsoft.XMLHTTP");
                         } catch (e){
                               /* Something went wrong */
                               ; /* uses default of false for AjaxObj */
                         }
                }
     }
        return AjaxObj;
}
</script>
{/literal}

 

The action:

<script type="text/javascript">

var countCart={$count_cart}
{literal}
function addToCart(item) {
if(!http) {return}
http.onreadystatechange=function() {
	if(http.readyState==4) {
		countCart++
		document.getElementById('countCart').innerHTML=countCart
	}
}
http.open("GET","include/ajax_cart_addto.php?sid={/literal}{$session_id}{literal}&product="+item,true)
http.send(null)
}

</script>
{/literal}

 

The HTML object:

Products in cart: <span id="countCart" style="font-weight: bold">{$count_cart}</span>

 

PHP for AJAX:

<?
require("db_config.php");

$sql="insert into webshop_cart (session_id,product) values ('$_GET[sid]',$_GET[product])";
sql_query($sql,$dbi) or die($sql);

?>

 

Result:

 

countCart increases by one, but only once, and only on HTML Object level, the AJAX action is not executed!! On reloading the page, countCart gets reset, proving that there was no change in the db.

 

It's obvious that the problem is that IE doesn't eat the AJAX part.

Why are things like Internet Explorer?! :(

Link to comment
Share on other sites

I can't pick through all your code but I know this code works in IE7. I'll gladly help because I know what a pain it is to get your http set up to work properly. This puts your http in a function though so that you can manipulate the function if you need it. I found if I didn't have my request in a function from the get go it messed me up. You will see at the end of this that it return the xmlhttp which means the http has been pulled and is then ready to go for the rest of your functions. You'll have to add the rest of your functions after the end of this. This is working code and works in all the important English browsers including IE.

 

function myNewXMLobject(){

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') {

try {

xmlhttp = new XMLHttpRequest();

} catch (e) {

xmlhttp=false;

}

}

if (!xmlhttp && window.createRequest) {

try {

xmlhttp = window.createRequest();

} catch (e) {

xmlhttp=false;

}

}if (!xmlhttp){

            // There is an error creating the object,

            // just as an old browser is being used.

            alert('There was a problem creating the XMLHttpRequest object');

        }

 

return xmlhttp;

}

Link to comment
Share on other sites

Thanks for helping, but it still doesn't work, although i tried under IE6, but IE6 is mostly normative anyway. :( Actually your code does only more by trying to create an ActiveXObject("Msxml2.XMLHTTP") too. I have also tried that before, with the same result. I'm pretty sure that the ActiveX object under IE gets created for me, coz i don't get error messages refferring on the object was failed to be created. The problem seems to be that this lousy MS XMLHttp doesn't work at all. How come it works for anyone else?? You can also see that the code i posted is minimal, so it should work.

 

It's sad that you can't put this down like "Who the fuck cares about IE users? They deserve this!" coz it's a matter of your website only. :(

Link to comment
Share on other sites

Believe me you are not alone, I myself was very frustrated with http when I first got it going, it took me months and it was a nightmare and few people helped me. I really believe there is something else wrong. Because it works for me every time, you just have to make sure a function is attached to it that works. What version of IE do you have? Also what browser are you using? Add this to the code I already gave you above, to the bottom of it and it should work. You have to upload your page with all this code in it. Then upload a page named testhttp.html as well. In testhttp.html stick in any old text. If its working it will add the text you put in testhttp.html and will put it in the div below named "countposts." If it doesn't work and no text was added let me know and I'll try to keep helping you for a bit until you get this working. I'll need you to try this though because http is so complicated it will take me too long to analyze your code when I already know this works. Then you can adjust whatever you need to fit to your own needs soon. But for now, first get this working and we'll go from there. Thats why a lot of people don't help with http, because reading the code is  very difficult.

 

Add to the bottom of my other code above.

// Make the XMLHttpRequest object 
    var http = myNewXMLobject();
     
    function sendRequest(act) { 
         
        // Open PHP script for requests 
        http.open('get', 'testhttp?act='+act); 
        http.onreadystatechange = handleResponse; 
        http.send(null); 
     
    } 
     
    function handleResponse() { 
     
        if(http.readyState == 4 && http.status == 200){ 
     
            // Text returned FROM testhttp.html
            var response = http.responseText; 
     
            if(response) { 
                // UPDATE ajaxTest content 
                document.getElementById("countPosts").innerHTML = response; 
          } 
     
        } 
    } 

    function countPosts() { 
        sendRequest('countPosts'); 
    } 


</script>
</head>
<body onload="countPosts();">
<div id="countPosts" style="border:1px solid black;height:100;width:150;color: rgb(255, 255, 255)"></div>
</body>
</html>

Link to comment
Share on other sites

Well, your code really did work!!

 

After comparing my code with yours, it turned out that IE didn't like some parts of my code:

 

  • IE didn't like that objectname.onreadystatechange preceded objectname.open()
  • IE didn't like this part of the code: http.open("GET",target=".............&product="+item) So i changed it to .....&product="+item+"&x=0")

 

So i fixed these two issues, and the page partially works now. But there is one more issue left, which i can't figure out. Please take a look at the target PHP, the point is that there is an sql query and a feedback for responseText:

<?
require("db_config.php");

$sql="insert into webshop_cart (session_id,product) values ('$_GET[sid]',$_GET[product])";
sql_query($sql,$dbi) or die($sql);

print $sql;
?>

 

The sql query only gets executed occasionally, while the responseText ("print $sql") appears all the time, eventhough the query is always correct (because if the query failed, it would exit before the "print $sql").

This may sound weird, but while testing, i was experiencing that when i emptied the cache, the query got sometimes executed, but never more than three times. After that, it never got executed till the next cache emptying. Weird, huh?

Have you had any experiences like this??

 

p.s.: everything i tested in IE, i tested in Firefox or Opera as well, and worked all the time.

Link to comment
Share on other sites

Isn't it nice to go from a very sad face to a little hope again??!!? Glad I could help.

Bad news is now your up with me. It took me a long time to get the code where it is and I don't know enough about http requests to be able to help you with the rest unfortunately. I'm afraid you'll have to find others that know more about requests. Maybe someone else will see this and help you here. Best wishes, you'll probably eventually get what you need.

Link to comment
Share on other sites

  • 1 month later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.