leafface Posted May 1, 2007 Share Posted May 1, 2007 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? Quote Link to comment Share on other sites More sharing options...
mainewoods Posted May 2, 2007 Share Posted May 2, 2007 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. Quote Link to comment Share on other sites More sharing options...
leafface Posted May 9, 2007 Author Share Posted May 9, 2007 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?! Quote Link to comment Share on other sites More sharing options...
11Tami Posted May 10, 2007 Share Posted May 10, 2007 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; } Quote Link to comment Share on other sites More sharing options...
leafface Posted May 10, 2007 Author Share Posted May 10, 2007 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. Quote Link to comment Share on other sites More sharing options...
11Tami Posted May 12, 2007 Share Posted May 12, 2007 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> Quote Link to comment Share on other sites More sharing options...
leafface Posted May 14, 2007 Author Share Posted May 14, 2007 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. Quote Link to comment Share on other sites More sharing options...
11Tami Posted May 14, 2007 Share Posted May 14, 2007 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. Quote Link to comment Share on other sites More sharing options...
leafface Posted May 14, 2007 Author Share Posted May 14, 2007 Well yeah, it sure is! Thanks a lot for your help! Now i know i don't have to forego AJAX because of IE. (I was thinking of it, coz i know another method that works similar than AJAX.) Cheers. Quote Link to comment Share on other sites More sharing options...
leafface Posted May 17, 2007 Author Share Posted May 17, 2007 This problem is solved as well. I've set IE to load the page on each visit, not just 'automatically', and this problem was over. Just how shit is Internet Explorer! I get surprised every day! Incredible. Quote Link to comment Share on other sites More sharing options...
11Tami Posted May 21, 2007 Share Posted May 21, 2007 Good deal glad its solved, just out of curiosity what was your other method using. Maybe I can use it, sometimes ajax drives me nuts. Thanks. Quote Link to comment Share on other sites More sharing options...
leafface Posted June 26, 2007 Author Share Posted June 26, 2007 Sorry for the late reply, i had to ask my boss, coz he was using this method, and i always forgot to. Here's a link to this method: http://www.webreference.com/programming/ajax_tech/ Since then i get on pretty well with the "common" XmlHttp Ajax, as now i know the unreasonable issues of IE. Cheers. Quote Link to comment Share on other sites More sharing options...
11Tami Posted June 28, 2007 Share Posted June 28, 2007 Thanks a lot face! I'm the opposite, my problems are always with mozilla and opera but glad its working! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.