{"id":73,"date":"2010-12-10T11:04:28","date_gmt":"2010-12-10T18:04:28","guid":{"rendered":"http:\/\/www.designersgate.com\/blogs\/?p=73"},"modified":"2010-12-10T11:04:28","modified_gmt":"2010-12-10T18:04:28","slug":"xmlhttprequest-error-in-ie8-and-9","status":"publish","type":"post","link":"https:\/\/designersgate.com\/blog\/xmlhttprequest-error-in-ie8-and-9\/","title":{"rendered":"XMLHttpRequest error in IE8 and 9"},"content":{"rendered":"<p>Don&#8217;t you hate when everything is going smoothly with your website, you haven&#8217;t done anything to it, it is the same since forever and suddenly&#8230;. Your ajax is not working in Internet Explorer. Suddenly customers start calling that they cannot log in, or documents are not displaying; A complete mess!!.<\/p>\n<p>Well it happens to me yesterday; since then I&#8217;ve been googling and binging for a solution and this is it. This is the solution that best suite my problems:<\/p>\n<pre>function getXML()\n{\n    var req;\n    try {\n        req = new XMLHttpRequest();\n    } catch (trymicrosoft) {\n        try {\n          req = new ActiveXObject(\"Msxml2.XMLHTTP\");\n        } catch (othermicrosoft) {\n          try {\n            req = new ActiveXObject(\"Microsoft.XMLHTTP\");\n          } catch (failed) {\n            req = null;\n          }\n        }\n    }\n\n    if (!req){\n\n      return null;\n    } else {\n       return req;\n    }\n}\n\nif(getXML()){\n    var xhttp = getXML();\n} else {\n    alert(\"Error initializing XMLHttpRequest!\");\n}<\/pre>\n<p>First of all I create a function to request the XMLHttpRequest Object, but as you know IE 5 and 6 doesn&#8217;t recognized this type of object so you need to catch the error and request an ActiveXObject(&#8220;Msxml2.XMLHTTP&#8221;) that might work with Internet Explorer 6 and 5 but for earlier versions you need to request an ActiveXObject(&#8220;Microsoft.XMLHTTP&#8221;) object.<\/p>\n<p>The problem I found is that I only request for the first two, following the sample code provided by w3schools.com, and it was perfect until yesterday. I need it to type back the old function as usual. Don&#8217;t know why? Probably MS is no longer accepting XMLHttpRequest or I don&#8217;t know I&#8217;m not a guru.<\/p>\n<p>The only thing I know this fixed my problem.<\/p>\n<p>Finally, I filter the code so if the xhttp variable is still null pop up a warning saying that the object was not loaded!<\/p>\n<p>Hope this help anyone, Happy Coding!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Don&#8217;t you hate when everything is going smoothly with your website, you haven&#8217;t done anything to it, it is the same since forever and suddenly&#8230;. Your ajax is not working in Internet Explorer. Suddenly customers start calling that they cannot log in, or documents are not displaying; A complete mess!!. Well it happens to me [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[62,13],"tags":[61,58,34,16,63,64],"class_list":["post-73","post","type-post","status-publish","format-standard","hentry","category-ie-solutions","category-tips","tag-ajax","tag-error","tag-ie","tag-javascript","tag-null","tag-object"],"acf":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/designersgate.com\/blog\/wp-json\/wp\/v2\/posts\/73","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/designersgate.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/designersgate.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/designersgate.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/designersgate.com\/blog\/wp-json\/wp\/v2\/comments?post=73"}],"version-history":[{"count":0,"href":"https:\/\/designersgate.com\/blog\/wp-json\/wp\/v2\/posts\/73\/revisions"}],"wp:attachment":[{"href":"https:\/\/designersgate.com\/blog\/wp-json\/wp\/v2\/media?parent=73"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/designersgate.com\/blog\/wp-json\/wp\/v2\/categories?post=73"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/designersgate.com\/blog\/wp-json\/wp\/v2\/tags?post=73"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}