giba Posted May 19, 2009 Share Posted May 19, 2009 Hi there! I am issuing a problem with IE that I can't solve it, because in all other browsers it work perfectly. I did a simple script that gets the HTML from an element by its class name, send it via ajax and gets the result from a .php file which contains a Google script for translation, the problem however is that only Internet explorer returns nothing. The question is: How can I send the HTML of an element and get it back on IE based on a loop that cicles AJAX requests? Follows de script I used: The code for getting the element by its class name: document.getElementsByClassName = function(class_name) { var docList = this.all || this.getElementsByTagName('*'); var matchArray = new Array(); var re = new RegExp("(?:^|\\s)"+class_name+"(?:\\s|$)"); for (var i = 0; i < docList.length; i++) { if (re.test(docList[i].className) ) { matchArray[matchArray.length] = docList[i]; } } return matchArray; } The code for looping through the elements with the class "translate": var trans = document.getElementsByClassName('translate'); for ( var i = 0; i < trans.length; i++) { t = trans[i]; translate(t,'translate.php?string='+escape(t.innerHTML.replace(/[\r\n]+/g, ""))+'&l=<?=$_GET['l'];?>&c='+Math.random()) } And the code for AJAX: function translate(target, url) { 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!"); } xmlhttp.onreadystatechange = function(){ if (xmlhttp.readyState == 4) { target.innerHTML = xmlhttp.responseText; //alert(xmlhttp.responseText); } } xmlhttp.open("GET", url, true); xmlhttp.send(null); } Link to comment https://forums.phpfreaks.com/topic/158743-solved-ajax-problems-with-internet-explorer-on-looping-a-collection-by-class-name/ Share on other sites More sharing options...
giba Posted May 20, 2009 Author Share Posted May 20, 2009 After dealing a lot with GET requests I found that IE limits the value of 500 charactes per value of a parameter in the Query String, so I dealt with this fragmenting my code in more peaces. Not the best choise, but works!!!! Link to comment https://forums.phpfreaks.com/topic/158743-solved-ajax-problems-with-internet-explorer-on-looping-a-collection-by-class-name/#findComment-838516 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.